If you have worked with JavaScript at any length you are aware that Internet Explorer does not implement the ECMAScript function for Array.prototype.indexOf() [including Internet Explorer 8].
(如果您曾经使用过JavaScript,那么您就会知道Internet Explorer不会为Array.prototype.indexOf()[包括Internet Explorer 8]实现ECMAScript函数。)
It is 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;
}
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?
(我是否应该使用以下检查将其包装在我的所有页面上,该检查将检查原型函数是否存在,如果不存在,请继续并扩展Array原型?)
if (!Array.prototype.indexOf) {
// Implement function here
}
Or do browser check and if it is Internet Explorer then just implement it?
(还是要检查浏览器,如果它是Internet Explorer,则只需实施它?)
//Pseudo-code
if (browser == IE Style Browser) {
// Implement function here
}
ask by Bobby Borszich translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…