From fa2d72b33705adccc74bf12e94e4e68d7261469c Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 4 Sep 2010 04:53:49 -0800 Subject: [PATCH] now isArray and instanceof works for arrays --- lib/traverse.js | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/traverse.js b/lib/traverse.js index 469d8ce..f436dfc 100644 --- a/lib/traverse.js +++ b/lib/traverse.js @@ -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); @@ -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; } diff --git a/package.json b/package.json index 54c278c..70cf34a 100644 --- a/package.json +++ b/package.json @@ -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",