montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.1k stars 183 forks source link

Using `Object.create(null)` instead of `{}` #119

Closed thefourtheye closed 9 years ago

thefourtheye commented 9 years ago

We use for..in or if..in more often in other functions, which will give us unexpected results with inherited properties from the prototype chain. So, its safer to use Object.create(null)

kriskowal commented 9 years ago

Note that Dict "mangles" the keys that are added to the internal dictionary store, so there is no chance of a collision with Object.prototype or __proto__. Object.create is unnecessary and limits backward-compatibility (though this is certainly not the longest pole in that tent).