If you have worked with JavaScript at any length you are aware that IE does not implement the ECMAScript function for Array.prototype.indexOf() [including IE8]. Not a huge problem because you can extend the functionality on your page with the following code.
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] == obj) { return i; }
}
return -1;
}
What I am looking for is when should I implement this?
should I wrap it on all my pages with the following check, which checks if the prototype function exists and if not go ahead and extend the Array prototype?
if (!Array.prototype.indexOf) {
//implement function here
}
or do browser check and if IE then just implement it?
//pseudo-code
if(browser == IE Style Browser) {
// implement function here
}