|
Post by iPokemon on Sept 5, 2011 23:48:52 GMT -5
Here is an on-going thing that I'll be working on in JS OOP, just to learn the properties and stuff.
Array.prototype.has=function(v){ for(x=0;x<this.length;x++){ if(this[x] == v) return true; } return false; } Array.prototype.isArray=function(){ if(typeof(this) == "object"){ if(this instanceof Array){ return true; } else { return false; } } else { return false; } } Array.prototype.isEmpty=function(){ for(x=0;x<this.length;x++){ if(this[x] != "") return true; } return false; } Array.prototype.valAt=function(i){ return this[i]; } Array.prototype.keyOf=function(v){ for(x=0;x<this.length;x++){ if(this[x] == v) return x; } return false; }
Functions:
var testarray = ["test","test2"]; testarray.has("test"); //returns true testarray.isArray(); //returns true testarray.isEmpty(); //returns false testarray.valAt(0); //returns test testarray.keyOf("test"); //returns 0
|
|