Skip to content

Commit

Permalink
key and value getters
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 27, 2010
1 parent 2d9f7a2 commit 459def9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Traverse = require('traverse');

function Hash (ref) {
var hash = Traverse.clone(ref);
return {
var self = {
map : function (f) {
var acc = { __proto__ : hash.__proto__ };
Object.keys(hash).forEach(function (key) {
Expand Down Expand Up @@ -35,8 +35,19 @@ function Hash (ref) {
});
return acc;
},
end : hash,
end : hash
};

Object.defineProperty(self, 'keys', { get : function () {
return Object.keys(hash);
} });

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

return self;
};

Hash.map = function (ref, f) {
Expand Down

0 comments on commit 459def9

Please sign in to comment.