简体   繁体   English

配置节点以使用Object.assign

[英]Configure Node to use Object.assign

I'm doing a simple test of Object.assign in both IO.js and Node.JS but its causing an error. 我在IO.js和Node.JS中对Object.assign进行了一个简单的测试,但是它导致了一个错误。

/Users/lp/.nvm/versions/io.js/v2.4.0/bin/iojs --debug-brk=59842 --nolazy mixin.js
Debugger listening on port 59842
/Users/lp/Documents/code/test/mixin.js:11
line = Object.assign(line, depth);
              ^
TypeError: Object.assign is not a function

Heres the code: 下面是代码:

var line = {
  x: 0,
  y: 0
};

var depth = {
  z: 0
};

line = Object.assign(line, depth);

I've tried Node v0.12.7 with --harmony and IO.js v2.4.0. 我用--harmony和IO.js v2.4.0尝试了Node v0.12.7。 From what I read ES6 should be supported. 从我读到的ES6应该得到支持。 Is assign not supported or am I missing something? 分配不支持或我错过了什么?

http://kangax.github.io/compat-table/es6 is the best place to look right now and it says Object.assign is unsupported on iojs and node. http://kangax.github.io/compat-table/es6是目前最好看的地方,它表示在iojs和节点上不支持Object.assign。 It's easy enough to load a polyfill though. 尽管如此,加载polyfill很容易。

The ES6 spec was only finalized last month, it isn't even close to fully implemented across platforms yet. ES6规范仅在上个月完成,它甚至还没有完全实现跨平台。 You should plan to rely on polyfills and transpilers like Babel and Traceur if you'd like to use larger portions of ES6 on current platforms. 如果您想在当前平台上使用较大部分的ES6,您应该计划依靠像Babel和Traceur这样的polyfill和transpilers。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM