js spread object

What’s is the benefit / drawback of these two alternatives?

Using object spread

options = {...optionsDefault, ...options};

Or using Object.assign

options = Object.assign({}, optionsDefault, options);

 

Code Sample (doubles as compatibility test)

var x = { a: 1, b: 2 };

var y = { c: 3, d: 4, a: 5 };

var z = {...x, ...y};

console.log(z); // { a: 5, b: 2, c: 3, d: 4 }

 

https://stackoverflow.com/questions/32925460/object-spread-vs-object-assign

posted @ 2019-07-12 12:02  zzfx  阅读(269)  评论(0编辑  收藏  举报