First of all, I want to say that I know that extending global methods is not a good practice, but there are situations where a developer needs to avoid duplicating objects due to size or other reasons, and global functions can help a lot in such situations.(at least that's what I believe)
I raised this topic because I think it's strange that this "bug" (example below) still exists in JavaScript, because if I'm not mistaken about 5 years ago I needed to traverse a window
object with a loop and I ended up finding it, but since so much time has passed and it still exists I think it might be normal for Object.prototype
Can anyone tell me if it's a forgotten bug or is it a normal occurrence? can't this be exploited as code injection along with this?
Object.prototype.foo = function(){
for(index in this) console.log(index)
}
var A = [1,2,3];
//returns a non-iterable index at the end
A.foo();
function bar(attr){
var B = {a:1, b:2,c:3}
for(index in B) console.log(index);
for(index in attr) console.log(index);
}
//all the 'in' iterations will start printing the index value at the end
bar([1,2,3,4,5]);
for(index in {x:1, y:2,z:3}) console.log(index);