javascript - Array.prototype.indexOf being added to end of arrays in IE8 -
i know ie8 , earlier doesn't have indexof function. i'm defining follows:
if (!array.prototype.indexof) { array.prototype.indexof = function(obj, start) { (var = (start || 0), j = this.length; < j; i++) { if (this[i] === obj) { return i; } } return -1; } }
i can correctly index of values in array, function being added end of arrays when using ie8 , earlier. therefore, i'm getting things like:
obj.obj2[0] = 'data' obj.obj2[1] = 'other data' obj.obj2['indexof'] = [definition of indexof function]
not surprisingly, breaking else on site. problem isn't happening in ie10 or 9. , appreciated.
it added prototype, everytime treat array object (for..in
loop 1 example), show up. not show in other browsers because have indexof
method default, you're not modifying prototype.
you can use obj.hasownproperty(propertyname)
test whether property defined directly on object (in case, array, object basically) or somewhere else in prototype chain.
Comments
Post a Comment