A few people I work with include on their sites some javascript I wrote and host. But some of those sites use prototype.js or some other framework and its causing some big problems.
For example:
var test = {"one":[{"a":"b"}]};
for (var i in test.one) { console.log(i); }
The expected result of this would be “0” in the console (i being the key to that array)
But if I go to a site like prototypejs.org and run the same code in firebug’s console, I get a list of all the prototype junk (each, eachSlice, etc..)
Try running it in your console here on stackoverflow, it returns “0” as expected.
How do I prevent this? Any good workarounds?
Either test that each property you enumerate is NOT in the prototype
or don’t enumerate arrays.
Any code that extends
Object.prototypeis not your problem. You should not have to guard against that.