3 ms·
A couple of notes, since this article appears quite dated. var hash = Object.create(null) creates an object free of inherited properties, this obviates mo
by lkey 11y ago
A couple of notes, since this article appears quite dated.
var hash = Object.create(null)
creates an object free of inherited properties, this obviates most of the need for a wrapper class for the "I just want an associative array" case.
For the "keys", "values", and "each" methods
In modern JS one could simply call
Object.keys(hash)
Object.keys(hash).map(function(key) { return hash[key] })
Object.keys(hash).forEach(function(key) { fn(key, hash[key]) })
respectively.
Or as the article suggests, simply use a library like Lodash for this kind of general purpose iteration.