Skip to content

Instantly share code, notes, and snippets.

@bpierre
Created May 5, 2012 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpierre/2603011 to your computer and use it in GitHub Desktop.
Save bpierre/2603011 to your computer and use it in GitHub Desktop.
hasOwnProperty style
var obj = {
foo: 1,
bar: 2
};
Object.prototype.oops = function(){};
// Meh.
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
// ...
}
}
// Better!
for (var key in obj) if (obj.hasOwnProperty(key)) {
// ...
}
@mauricesvay
Copy link

Pretty neat.

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