diff --git a/lib/deap.js b/lib/deap.js index 386eb92..db22d53 100755 --- a/lib/deap.js +++ b/lib/deap.js @@ -26,7 +26,7 @@ function clone(val) { function extend(a, b /*, [b2..n] */) { slice.call(arguments, 1).forEach(function(b) { - Object.getOwnPropertyNames(b).forEach(function(p) { + Object.keys(b).forEach(function(p) { a[p] = b[p]; }); }); @@ -35,7 +35,7 @@ function extend(a, b /*, [b2..n] */) { function deepExtend(a, b /*, [b2..n] */) { slice.call(arguments, 1).forEach(function(b) { - Object.getOwnPropertyNames(b).forEach(function(p) { + Object.keys(b).forEach(function(p) { if(typeOf(b[p]) === 'object' && typeOf(a[p]) === 'object') deepExtend(a[p], b[p]); else @@ -47,7 +47,7 @@ function deepExtend(a, b /*, [b2..n] */) { function merge(a, b /*, [b2..n] */) { slice.call(arguments, 1).forEach(function(b) { - Object.getOwnPropertyNames(b).forEach(function(p) { + Object.keys(b).forEach(function(p) { if(a.hasOwnProperty(p)) a[p] = b[p]; }); }); @@ -57,7 +57,7 @@ function merge(a, b /*, [b2..n] */) { function deepMerge(a, b /*, [b2..n] */) { slice.call(arguments, 1).forEach(function(b) { var ap, bp, ta, tb; - Object.getOwnPropertyNames(b).forEach(function(p) { + Object.keys(b).forEach(function(p) { if(a.hasOwnProperty(p)) { ap = a[p]; bp = b[p]; diff --git a/test/extend.test.js b/test/extend.test.js index abc64d4..aeeb9de 100755 --- a/test/extend.test.js +++ b/test/extend.test.js @@ -80,6 +80,14 @@ describe('shallow extend', function() { assert.strictEqual(result.array, array); }); + + it('should not pick up non-enumberable properties', function() { + var result = shallow({}, function() {}); + + assert.deepEqual(result, {}); + assert.equal(Object.keys(result).length, 0); + assert.equal(Object.getOwnPropertyNames(result).length, 0); + }); }); describe('deep extend', function() {