diff --git a/lodash.js b/lodash.js index b339dcaa9..db140d32f 100644 --- a/lodash.js +++ b/lodash.js @@ -587,18 +587,6 @@ return false; } - /** - * Used by `_.defaults` to customize its `_.assignIn` use. - * - * @private - * @param {*} objValue The destination object property value. - * @param {*} srcValue The source object property value. - * @returns {*} Returns the value to assign to the destination object. - */ - function assignInDefaults(objValue, srcValue) { - return objValue === undefined ? srcValue : objValue; - } - /** * Assigns `value` to `key` of `object` if the existing value is not equivalent * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) @@ -2137,6 +2125,21 @@ /*------------------------------------------------------------------------*/ + /** + * Used by `_.defaults` to customize its `_.assignIn` use. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to assign. + * @returns {*} Returns the value to assign. + */ + function assignInDefaults(objValue, srcValue, key) { + return (objValue === undefined || objValue === objectProto[key]) + ? srcValue + : objValue; + } + /** * The base implementation of `_.assign` without support for multiple sources * or `customizer` functions. @@ -4853,9 +4856,9 @@ * Used by `_.defaultsDeep` to customize its `_.merge` use. * * @private - * @param {*} objValue The destination object property value. - * @param {*} srcValue The source object property value. - * @returns {*} Returns the value to assign to the destination object. + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @returns {*} Returns the value to assign. */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { if (isObject(objValue) && isObject(srcValue)) { diff --git a/test/test.js b/test/test.js index c1b1501c6..ea831665b 100644 --- a/test/test.js +++ b/test/test.js @@ -3626,6 +3626,13 @@ var actual = _.defaults({ 'a': undefined }, { 'a': 1 }); assert.strictEqual(actual.a, 1); }); + + QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) { + assert.expect(1); + + var actual = _.defaults({}, { 'constructor': 1 }); + assert.strictEqual(actual.constructor, 1); + }); }()); /*--------------------------------------------------------------------------*/