From 4319cdbba1f6b799a9360b28561201e1f2b8ec38 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 27 Dec 2014 21:14:12 -0600 Subject: [PATCH] Fix failing Backbone test and ensure `_.assign` works properly with a `customizer` that returns `undefined`. --- lodash.js | 9 +++++---- test/test.js | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 823357d7d..af44453c9 100644 --- a/lodash.js +++ b/lodash.js @@ -1694,11 +1694,12 @@ if (customizer) { var value = object[key], result = customizer(value, source[key], key, object, source); + + if (result !== value || (typeof value == 'undefined' && !(key in object))) { + object[key] = result; + } } else { - result = source[key]; - } - if (!(customizer && result === value)) { - object[key] = result; + object[key] = source[key]; } } return object; diff --git a/test/test.js b/test/test.js index 9910412d3..eb294592b 100644 --- a/test/test.js +++ b/test/test.js @@ -953,6 +953,11 @@ deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 }); }); + test('should work with a `customizer` that returns `undefined`', 1, function() { + var expected = { 'a': undefined }; + deepEqual(_.assign({}, expected, _.identity), expected); + }); + test('should be aliased', 1, function() { strictEqual(_.extend, _.assign); });