Add method to Array object : prototype : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » prototype »

 

Add method to Array object













Array.prototype.enqueue = function(vItem) {
    this.push(vItem);
};

Array.prototype.dequeue = function() {
    return this.shift();
};
Array.prototype.indexOf = function (vItem) {
    for (var i=0; i < this.length; i++) {
        if (vItem == this[i]) {
            return i;
        }
    }
    return -1;
}
var aColors = new Array("red""green""yellow");
alert(aColors.indexOf("green"));







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» prototype