Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
avoid transforming functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ruffle1986 committed Oct 1, 2015
1 parent 63df83f commit f96ea5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function toObject(val) {
return Object(val);
}

function isFunc(val) {
return typeof val === 'function';
}

function base(to, from) {
if (to === from) {
return to;
Expand All @@ -24,7 +28,7 @@ function base(to, from) {

if (Array.isArray(val)) {
to[key] = val.slice();
} else if (isObj(val)) {
} else if (isObj(val) && !isFunc(val)) {
to[key] = base(to[key] || {}, val);
} else if (val !== undefined) {
to[key] = val;
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ if (typeof Symbol !== 'undefined') {
t.end();
});
}

test('do not transform functions', t => {
var target = {
foo: function bar() {}
};
var source = {};
t.is(typeof fn({}, target, source).foo, 'function');
t.end();
});

0 comments on commit f96ea5e

Please sign in to comment.