Created
November 3, 2015 15:07
-
-
Save oakfang/dd0429f4dbf23a9e40ee to your computer and use it in GitHub Desktop.
Prototype and for...in
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
// using ES5, but still relevant | |
var map = { | |
a: 1, | |
b: 2 | |
}; | |
Object.prototype.thisIsReallyReallyPrivate = 'foo' | |
for (var key in map) { | |
console.log(key); | |
// a | |
// b | |
// thisIsReallyReallyPrivate | |
} | |
// instead use: | |
function newMap() {return Object.create(null)} | |
map = newMap(); | |
map.a = 1; | |
map.b = 2; | |
for (var key in map) { | |
console.log(key); | |
// a | |
// b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment