Skip to content

Commit

Permalink
untested get and set
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jun 3, 2011
1 parent 6fe06a5 commit 7fa7247
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ function Traverse (obj) {
this.value = obj;
}

Traverse.prototype.get = function (ps) {
var node = this.value;
for (var i = 0; i < ps.length; i ++) {
if (!Object.hasOwnProperty.call(node, key)) {
node = undefined;
break;
}
node = node[ps[i]];
}
return node;
};

Traverse.prototype.set = function (ps, value) {
var node = this.value;
for (var i = 0; i < ps.length - 1; i ++) {
var key = ps[i];
if (!Object.hasOwnProperty.call(node, key)) node[key] = {};
node = node[key];
}
node[ps[i]] = value;
return value;
};

Traverse.prototype.map = function (cb) {
return walk(this.value, cb, true);
};
Expand Down

0 comments on commit 7fa7247

Please sign in to comment.