Created
May 5, 2012 14:45
-
-
Save bpierre/2603011 to your computer and use it in GitHub Desktop.
hasOwnProperty style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty neat.