javascript - Object.assign 和 just assign 的区别

标签 javascript node.js

我想知道这之间的区别:

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/

相关文章:

node.js - 安装并吞掉插件

javascript - node.js express js flash 消息 ajax

javascript - 两个类的关注点分离

javascript - 如何将 datepicker 日期转换为 JSON 对象以在 AJAX 请求中使用

node.js - 用于传感器数据收集的 MongoDB 查询

node.js - Zombie Js如何在特定情况下使用

javascript - 如何在minimatch中匹配一次html或js?

node.js - ETXTBSY : text file is busy when running npm install (via Vagrant with Unix - Desktop OS is Windows)

javascript - 使用 JavaScript 更改 SVG 图像的大小?

javascript - Durandal 2.0 - 更新 View 中可观察值的值