diff --git a/lodash.js b/lodash.js index 53e11479b..bdda33f26 100644 --- a/lodash.js +++ b/lodash.js @@ -2189,12 +2189,15 @@ * @param {*} objValue The destination value. * @param {*} srcValue The source value. * @param {string} key The key of the property to assign. + * @param {Object} object The parent object of `objValue`. * @returns {*} Returns the value to assign. */ - function assignInDefaults(objValue, srcValue, key) { - return (objValue === undefined || objValue === objectProto[key]) - ? srcValue - : objValue; + function assignInDefaults(objValue, srcValue, key, object) { + if (objValue === undefined || + (objValue === objectProto[key] && !hasOwnProperty.call(object, key))) { + return srcValue; + } + return objValue; } /** diff --git a/test/test.js b/test/test.js index f7921ff60..417c26499 100644 --- a/test/test.js +++ b/test/test.js @@ -3606,10 +3606,15 @@ }); QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) { - assert.expect(1); + assert.expect(2); + + var ctor = objectProto.constructor, + actual = _.defaults({}, { 'constructor': 1 }); - var actual = _.defaults({}, { 'constructor': 1 }); assert.strictEqual(actual.constructor, 1); + + actual = _.defaults({ 'constructor': ctor }, { 'constructor': 1 }); + assert.strictEqual(actual.constructor, ctor); }); }());