spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column59


IE 5.5: Formatting, URIs, and Stack Operations

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

The Code

<HTML>
<HEAD>
<TITLE>A Push Demo</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function bName() {
  if (navigator.appName == "Microsoft Internet Explorer")
    return 1;
  if (navigator.appName == "Netscape")
    return 2;
  return 0;
}

function bVer() {
  // return version number (e.g., 4.03)
  msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
  return(parseFloat(navigator.appVersion.substr(msieIndex,3)));
}

function push() {
  var sub = this.length;
  for (var i = 0; i < push.arguments.length; ++i) {
    this[sub] = push.arguments[i];
	sub++;
  }
}

function pop() {
  var lastElement = this[this.length - 1];
  this.length--;
  return lastElement;
}

function shift(str) {
  var val = this[0];
  for (var i = 1; i < this.length; ++i) {
    this[i-1] = this[i];
  }
  this.length--;
  return val;
}

function unshift() {
  var i = unshift.arguments.length;
  for (var j = this.length - 1; j >= 0; --j) {
    this[j + i] = this[j];
  }
  for (j = 0; j < i; ++j) {
    this[j] = unshift.arguments[j];
  }
}

if (bName() == 1 && bVer() >= 5.5);
else {
  Array.prototype.push = push;
  Array.prototype.pop = pop;
  Array.prototype.shift = shift;
  Array.prototype.unshift = unshift;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
var names = new Array("Tom", "Mark", "Bart", "John");
names.push("Jim", "Richard", "Tim");
alert(names);

var names = new Array("Tom", "Mark", "Bart", "Jonn");
var last = names.pop();
alert("Last = " + last + "  Other = " + names);

var line = new Array("aaa", "bbb", "ccc", "ddd", "eee");
alert("First = " + line.shift() + " Other = " + line);

var line = new Array("ccc", "ddd", "eee");
line.unshift("aaa", "bbb");
alert(line);

</SCRIPT>
</BODY>
</HTML>

Next: A Final Word

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji


Created: March 14, 2000
Revised: April 26, 2000

URL: http://www.webreference.com/js/column59/8.html