Skip to content

Commit

Permalink
Fixed issue causing non-enumerable properties to get copied
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Dunlap committed May 8, 2013
1 parent 1fd6180 commit 2056d70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/deap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
});
Expand All @@ -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
Expand All @@ -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];
});
});
Expand All @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions test/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2056d70

Please sign in to comment.