Closed donavon closed 6 years ago
Ah, right, good catch~! I'll fix this, but we should also be paving on null
value too.
Slightly unrelated, but thoughts about not throwing if a value exists? Instead, would silently break & exit.
I wouldn't pave over a null
as it is an actual value.
I'm a big fan of throwing when there is an exception. Hiding/masking the problem will make it harder to track down the root cause.
Actually, you might want to use this instead:
x = keys[i] in o ? o[keys[i]] : {};
That'd throw immediately for anything that isn't already an object, including undefined
s 😆 That's probably what you want, except for the latter.
In your example, if
foo.d
is already set to say5
, it throws. I would expect that. However, if it is0
(or anything falsey), it paves over the falsey value.A possible fix is: