diff --git a/lib/traverse.js b/lib/traverse.js index b10e657..a2cddc2 100644 --- a/lib/traverse.js +++ b/lib/traverse.js @@ -12,7 +12,7 @@ function Traverse (refObj) { node[key] = clone(ref[key]); }); // To make instanceof work: - if ('__proto__' in ref) node.__proto__ = ref.__proto__; + node.__proto__ = ref.__proto__; // Probably there are other attributes worth copying return node; } diff --git a/test/instance.js b/test/instance.js new file mode 100755 index 0000000..62c5c5b --- /dev/null +++ b/test/instance.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node +var sys = require('sys'); +var Traverse = require('traverse'); +var EventEmitter = require('events').EventEmitter; + +exports['check instanceof on node elems'] = function (assert) { + + var counts = { emitter : 0 }; + + Traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }]) + .forEach(function (node) { + if (node instanceof EventEmitter) counts.emitter ++; + }) + ; + + assert.equal(counts.emitter, 2); +}; +