I want to create a prototype of forEach on objects and here is my code
Object.prototype.forEach = function(el,index){
for(var k in Object){
el = Object[k];
index = k;
}
}
Then i created an object to test this
var obj = {x:0,y:0,z:1290}
obj.forEach( function(el, index) {
console.log(el+" "+index);
alert();
});
This code returns no errors,but neither does it alert or log into console anything. I checked obj
object and it does have forEach in it's _proto_
property.I also tried
Object.prototype.forEach = function(el,index){
for(var k in this){
el = this[k];
index = k;
}
}