我想知道这之间的区别:
Object.assign(otherObject, {
someNewProperty: ''
});
和
otherObject.someNewProperty = '';
还有..哪个更快?
谢谢。
最佳答案
The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.
而 otherObject.someNewProperty = '';
是一种直接为对象的某些属性赋值的方法。
显然 Object.assign
模式要慢得多:jsperf.com/assign-vs-equals
关于javascript - Object.assign 和 just assign 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35241790/