Let's say I want to declare an object bar
and set it's values to be those of the object foo
, but I'm uncertain whether foo
will have all the requisite properties. I also want to preserve falsy values like ""
from foo
, rather than reverting to defaults. For example:
var foo = somefunc();
console.log(foo);
//{prop1: "", prop2: "works"}
var defaults = {prop1: "default1", prop2: "default2", prop3: "default3"}
/* some piece of code */
console.log(bar);
//should log: {prop1: "", prop2: "works", prop3: "default3"}
What would be the best /* some piece of code */
to use in Ecmascript 6 to initialize with defaults like this?