Skip to content

Conversation

@OverZealous
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant