Skip to content

Commit

Permalink
[Fix] deep extending should work with a non-object.
Browse files Browse the repository at this point in the history
Fixes #46.
  • Loading branch information
ljharb committed Apr 25, 2017
1 parent fd71078 commit eee260c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -7,7 +7,7 @@
"complexity": [2, 15],
"eqeqeq": [2, "allow-null"],
"max-depth": [1, 4],
"max-statements": [2, 25],
"max-statements": [2, 26],
"no-extra-parens": [1],
"no-magic-numbers": [0],
"no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"]
Expand Down
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -44,7 +44,8 @@ module.exports = function extend() {
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
} else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
}
if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
target = {};
}

Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Expand Up @@ -619,3 +619,10 @@ test('works without Array.isArray', function (t) {
Array.isArray = savedIsArray;
t.end();
});

test('non-object target', function (t) {
t.deepEqual(extend(3.14, { a: 'b' }), { a: 'b' });
t.deepEqual(extend(true, 3.14, { a: 'b' }), { a: 'b' });

t.end();
});

0 comments on commit eee260c

Please sign in to comment.