mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Ensure assignValue assigns values if they aren't the same own value. [closes #2022]
This commit is contained in:
@@ -2160,8 +2160,7 @@
|
|||||||
*/
|
*/
|
||||||
function assignValue(object, key, value) {
|
function assignValue(object, key, value) {
|
||||||
var objValue = object[key];
|
var objValue = object[key];
|
||||||
if ((!eq(objValue, value) ||
|
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
||||||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
|
|
||||||
(value === undefined && !(key in object))) {
|
(value === undefined && !(key in object))) {
|
||||||
object[key] = value;
|
object[key] = value;
|
||||||
}
|
}
|
||||||
|
|||||||
10
test/test.js
10
test/test.js
@@ -3497,6 +3497,16 @@
|
|||||||
assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
|
assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
function Foo() {
|
||||||
|
this.a = 1;
|
||||||
|
}
|
||||||
|
var object = _.create(new Foo, { 'a': 1 });
|
||||||
|
assert.deepEqual(lodashStable.keys(object), ['a']);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should accept a falsey `prototype` argument', function(assert) {
|
QUnit.test('should accept a falsey `prototype` argument', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user