Possible Duplicate:
Is it an anti-pattern to modify JavaScript's built-in prototypes?
I just learned that it's possible to modify the JavaScript core objects, but the same article that told me how to do it suggested that I never should.
Is it a bad thing to modify a core JS object? If so, what problems could this cause?
As an example, here's a modification of the Array object that gives me an easy way to search for a given value in an array:
Array.prototype.search = function(val){
var i;
for (i = 0; i < this.length; i++){
if (this[i] == val) {
console.log("found: " + val);
return true;
}
}
console.log("didn't find it");
return false;
};
Here's the article: Advanced Javascript: Objects, Arrays, and Array-Like objects