Add methods to built-in objects: // Does an array contain element x ? function contains( x ) { for (var i=0; i<this.length; i++) { if (this[i] == x) return true; } return false; } |
Add the method to the Array object with the prototype property: Array.prototype.contains = contains; |