Browse files

Use the features of Hash a little.

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

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

@creationix
Owner

Besides, forEach and map aren't enumerable, so for..in 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
}}
});
Object.freeze(Hash);
View
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());
});
},

0 comments on commit 7f4e660

Please sign in to comment.