I'm working in a large legacy codebase and just realized that someone did this:
Array.prototype.insertAt = function (i,el){ return this.splice(i,0,el); }
Array.prototype.deleteAt = function (i){return this.splice(i, 1); }
and that this is the reason i can't to this:
var derp = new Array();
derp.push('duh');
derp.push('what?');
for (var i in derp) {
console.log(derp[i]);
}
Well, it's not that i can't do it, but if i do, i get unexpected results. That being instead of getting two lines of output (for 'duh' and 'what?') i get four. the last two being the two functions listed above.
I don't want to remove the original prototype functions (because god knows what depends on them), but i am wondering if there is a way to prevent the for loop from looping over the functions that were added.