plugd
plugd copied to clipboard
Added hasOwnProperty to forIn
I've wrapped the callback method in a hasOwnProperty check. This is generally considered good behavior, as it prevents modification of the default prototype from affecting hashmaps. Link to the JSLint page on the subject.
Example (really) bad code:
// modify the base prototype
Object.prototype.foo = "bar";
// create a map to iterator over
var hashmap = { baz: "foo" };
// iterates over all inherited properties (for better or for worse)
for(var k in hashmap) {
console.log(hashmap[k]);
}
// outputs:
// bar
// foo
Now, I suppose it could be argued that the check should be optional.