Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use the features of Hash a little.

  • Loading branch information...
commit 7f4e6605d628aa9f1ea210eec9e1616c5a187ef7 1 parent 446d3fd
@creationix authored
Showing with 5 additions and 2 deletions.
  1. +3 −0  lib/hash.js
  2. +2 −2 lib/nstore.js
3  lib/hash.js
@@ -27,6 +27,9 @@ var Hash = module.exports = Object.create(Object.prototype, {
accum[i] =, this[key], key, this);
return accum;
+ }},
+ length: {get: function length() {
+ return Object.keys(this).length;
herby added a note

This is not right (I think), keys returns all enumerable properties, that is, alaso methods inhertied from prototype.... getOwnProperties, maybe, really return length of the hash... that is, I think is at least 2 (for forEach and map)...

@creationix Owner

No, Object.keys explicitly only grabs enumerable keys from the object, not it's prototypes.

herby added a note

Yes, you're right, sorry. I thought it is on par with for-in.

@creationix Owner

Besides, forEach and map aren't enumerable, so would even work, just a lot slower. And if someone messed with Object.prototype then it might break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 lib/nstore.js
@@ -28,7 +28,7 @@ var nStore = module.exports = Class.extend({
// getter property that returns the number of documents in the database
get length() {
- return Object.keys(this.index).length;
+ return this.index.length;
getKey: function getKey() {
@@ -142,7 +142,7 @@ var nStore = module.exports = Class.extend({
- Object.keys(self.index).forEach(function (key) {
+ self.index.forEach(function (info, key) {
copy(key, group());
Please sign in to comment.
Something went wrong with that request. Please try again.