Skip to content

Commit

Permalink
Merge pull request keen#106 from srapp/fix-deep-extend
Browse files Browse the repository at this point in the history
Don't attempt to clone a function attribute in deepExtend
  • Loading branch information
grain209 authored Apr 20, 2018
2 parents cc2214a + 60bd81a commit 171272a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/keen-tracking.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/keen-tracking.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/utils/deepExtend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function deepExtend(target){
deepExtend(target[prop], clone(arguments[i][prop]));
}
// Otherwise just copy it over...
else if (arguments[i][prop] !== undefined) {
else if (arguments[i][prop] !== undefined && 'function' !== typeof arguments[i][prop]) {
target[prop] = clone(arguments[i][prop]);
}
}
Expand Down
32 changes: 29 additions & 3 deletions test/unit/modules/utils/deep-extend-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ describe('Keen.utils.deepExtend', function() {
a5: 'a5'
},
b: [],
c: [ 1, 2, 3 ]
c: [ 1, 2, 3 ],
d: {
value: 'd1'
}
};

var b = {
Expand All @@ -28,7 +31,11 @@ describe('Keen.utils.deepExtend', function() {
}
},
b: false,
c: [ '3', 3, 5 ]
c: [ '3', 3, 5 ],
d: {
value: 'd2',
f: function() {}
}
};

assert.deepEqual(deepExtend(a, b), {
Expand All @@ -42,7 +49,26 @@ describe('Keen.utils.deepExtend', function() {
a5: 'a5'
},
b: false,
c: [ 1, 2, 3, '3', 5 ]
c: [ 1, 2, 3, '3', 5 ],
d: {
value: 'd2'
}
});

});

it('should not blend function attributes', function() {
var a = {
value: 'a'
};

var b = {
value: 'b',
f: function() {}
};

assert.deepEqual(deepExtend(a, b), {
value: 'b'
});

});
Expand Down

0 comments on commit 171272a

Please sign in to comment.