We can add methods to built-in objects, too: // 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; } |
Now add the method to the Array object with the prototype property: Array.prototype.contains = contains; |