Skip to content

Commit

Permalink
now isArray and instanceof works for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 4, 2010
1 parent 6683529 commit fa2d72b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Traverse (refObj) {
clone.nodes = [];
function clone(ref) {
if (typeof ref == 'object' && ref !== null) {
var node = ref instanceof Array ? [] : {};
var node = Array.isArray(ref) ? [] : {};
clone.refs.push(ref);
clone.nodes.push(node);

Expand All @@ -30,7 +30,8 @@ function Traverse (refObj) {
clone.nodes.pop();

// To make instanceof work:
node.__proto__ = ref.__proto__;
if (!Array.isArray(ref)) node.__proto__ = ref.__proto__;

// Probably there are other attributes worth copying
return node;
}
Expand Down
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.1.2",
"version" : "0.1.3",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"author" : "James Halliday",
"license" : "MIT/X11",
Expand Down

0 comments on commit fa2d72b

Please sign in to comment.