Skip to content

Commit

Permalink
take out memoization since it breaks if the hash gets modified outsid…
Browse files Browse the repository at this point in the history
…e the fluent interface
  • Loading branch information
James Halliday committed Sep 9, 2010
1 parent 0226636 commit 67b6d3d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,13 @@ function Hash (hash, xs) {
items : hash
};

var memoized = {};
Object.defineProperty(self, 'keys', { get : function () {
if (memoized.keys === undefined) {
memoized.keys = Object.keys(hash);
}
return memoized.keys
return Object.keys(hash);
} });

Object.defineProperty(self, 'values', { get : function () {
if (memoized.values === undefined) {
memoized.values = Object.keys(hash)
.map(function (key) { return hash[key] });
}
return memoized.values;
return Object.keys(hash)
.map(function (key) { return hash[key] });
} });

Object.defineProperty(self, 'compact', { get : function () {
Expand All @@ -109,10 +102,7 @@ function Hash (hash, xs) {
} });

Object.defineProperty(self, 'length', { get : function () {
if (memoized.length === undefined) {
memoized.length = Object.keys(hash).length;
}
return memoized.length;
return Object.keys(hash).length;
} });

return self;
Expand Down

0 comments on commit 67b6d3d

Please sign in to comment.