js spread object

时间:2019-07-12 14:29:07   收藏:0   阅读:60

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

原文:https://www.cnblogs.com/feng9exe/p/11175323.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!