From 04aa82538db6f38b19af48da130039250cc526bb Mon Sep 17 00:00:00 2001 From: Elena Paraschiv Date: Sun, 20 Aug 2017 20:13:44 +0200 Subject: [PATCH] Solves an inconsistency inside defaults function The comment in line 87 is inaccurate ```Replace values with defaults only if undefined (allow empty/zero values) ``` __ Problem:__ We try to pass in 2 objects inside defaults function and we get an unexpected result. ``` defaults({color: null}, {color:'grey', wheels:2}) // returns {color: "grey", wheels: 2} ``` This output shows that the null value is overwritten by the defs value. This is inaccurate and inconsistent with the comment. __Solution:__ With this fix, the expected output is corrected to return ``` {color: null, wheels: 2}, ``` --- accounting.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/accounting.js b/accounting.js index fd181fd..d69aef3 100644 --- a/accounting.js +++ b/accounting.js @@ -85,7 +85,9 @@ for (key in defs) { if (defs.hasOwnProperty(key)) { // Replace values with defaults only if undefined (allow empty/zero values): - if (object[key] == null) object[key] = defs[key]; + if (object[key] === undefined) { + object[key] = defs[key]; + } } } return object;