Skip to content

Instantly share code, notes, and snippets.

@oakfang
Created November 3, 2015 15:07
Show Gist options
  • Save oakfang/dd0429f4dbf23a9e40ee to your computer and use it in GitHub Desktop.
Save oakfang/dd0429f4dbf23a9e40ee to your computer and use it in GitHub Desktop.
Prototype and for...in
// 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