mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Refine Object.prototype check in _.defaults.
This commit is contained in:
11
lodash.js
11
lodash.js
@@ -2189,12 +2189,15 @@
|
|||||||
* @param {*} objValue The destination value.
|
* @param {*} objValue The destination value.
|
||||||
* @param {*} srcValue The source value.
|
* @param {*} srcValue The source value.
|
||||||
* @param {string} key The key of the property to assign.
|
* @param {string} key The key of the property to assign.
|
||||||
|
* @param {Object} object The parent object of `objValue`.
|
||||||
* @returns {*} Returns the value to assign.
|
* @returns {*} Returns the value to assign.
|
||||||
*/
|
*/
|
||||||
function assignInDefaults(objValue, srcValue, key) {
|
function assignInDefaults(objValue, srcValue, key, object) {
|
||||||
return (objValue === undefined || objValue === objectProto[key])
|
if (objValue === undefined ||
|
||||||
? srcValue
|
(objValue === objectProto[key] && !hasOwnProperty.call(object, key))) {
|
||||||
: objValue;
|
return srcValue;
|
||||||
|
}
|
||||||
|
return objValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3606,10 +3606,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
|
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);
|
assert.strictEqual(actual.constructor, 1);
|
||||||
|
|
||||||
|
actual = _.defaults({ 'constructor': ctor }, { 'constructor': 1 });
|
||||||
|
assert.strictEqual(actual.constructor, ctor);
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user