From bfbfa719ff278d8f27410d0b67de754a20a96d15 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 18 Feb 2016 22:17:49 -0800 Subject: [PATCH] Ensure `assignValue` assigns values if they aren't the same own value. [closes #2022] --- lodash.js | 3 +-- test/test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index 854d9edae..a67be636b 100644 --- a/lodash.js +++ b/lodash.js @@ -2160,8 +2160,7 @@ */ function assignValue(object, key, value) { var objValue = object[key]; - if ((!eq(objValue, value) || - (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) || + if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || (value === undefined && !(key in object))) { object[key] = value; } diff --git a/test/test.js b/test/test.js index f98481ca9..7e02f45d9 100644 --- a/test/test.js +++ b/test/test.js @@ -3497,6 +3497,16 @@ 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) { assert.expect(1);