From 459def9529e381d38909f75b182b330e20d3f2f9 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 26 Aug 2010 18:20:53 -0800 Subject: [PATCH] key and value getters --- lib/hash.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/hash.js b/lib/hash.js index a60c418..60b73fa 100644 --- a/lib/hash.js +++ b/lib/hash.js @@ -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) { @@ -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) {