Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hasOwnProperty to forIn #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Added hasOwnProperty to forIn #2

wants to merge 1 commit into from

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