Skip to content

Commit

Permalink
special check for null, for which typeof(null) == 'object'
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 14, 2010
1 parent 590045e commit a4128c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "traverse",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"author" : "James Halliday",
"main" : "traverse",
Expand Down
16 changes: 10 additions & 6 deletions traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ function Traverse (obj) {
parent : parents.slice(-1)[0],
key : path.slice(-1)[0],
isRoot : node == obj,
notRoot : node != obj,
isLeaf : typeof(node) != 'object'
|| Object.keys(node).length == 0,
notLeaf : typeof(node) == 'object'
&& Object.keys(node).length > 0,
update : function (x) {
if (state.isRoot) {
obj = x;
Expand All @@ -33,9 +28,18 @@ function Traverse (obj) {
},
level : path.length,
};
if (typeof(node) == 'object' && node !== null) {
state.isLeaf = Object.keys(node).length == 0
}
else {
state.isLeaf = true;
}

state.notLeaf = !state.isLeaf;
state.notRoot = !state.isRoot;

f.call(state, node);
if (typeof(state.node) == 'object') {
if (typeof(state.node) == 'object' && state.node !== null) {
parents.push(state);
Object.keys(state.node).forEach(function (key) {
path.push(key);
Expand Down

0 comments on commit a4128c0

Please sign in to comment.