diff --git a/.eslintrc b/.eslintrc index 25241e2..d469692 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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"] diff --git a/index.js b/index.js index ff51827..bbe53f6 100644 --- a/index.js +++ b/index.js @@ -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 = {}; } diff --git a/test/index.js b/test/index.js index 92a73a3..1a5c087 100644 --- a/test/index.js +++ b/test/index.js @@ -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(); +});