简体   繁体   English

ES6默认参数?

[英]ES6 default parameters?

I'm trying to use default parameter values, but getting this error: 我正在尝试使用默认参数值,但收到此错误:

SyntaxError: Unexpected token =

Is this working in node now? 这现在在节点中工作吗? I'm using 5.9.1 我正在使用5.9.1

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/default_parameters https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/default_parameters

I also tried messing with passing flags to node without success. 我也尝试过将标志传递给节点而没有成功。

  node --harmony_default_parameters

It seems like a basic part of ES6 so hope it would be working by now! 它似乎是ES6的基本部分,所以希望它现在可以工作!

Is this working in node now? 这现在在节点中工作吗?

Not yet. 还没。 It's only available for testing under a flag. 它仅适用于旗帜下的测试。 V8 v4.9 (released in Chrome 49) is the earliest stable version of V8 that supports default parameters. V8 v4.9(在Chrome 49中发布)是最早的V8稳定版本,支持默认参数。 Nodejs v5.9.1 runs on top of V8 v4.6.85.31 . Nodejs v5.9.1运行在V8 v4.6.85.31 You can use the command node -p process.versions.v8 for checking the current V8 version. 您可以使用命令node -p process.versions.v8来检查当前的V8版本。 Also, you have to wait until Nodejs v6.x for a complete support of default parameters. 此外,您必须等到Nodejs v6.x才能完全支持默认参数。 You can see this issue for more details. 您可以查看此问题以获取更多详细信息。

The problem seems to be a result of mixing ES6 style functions: 问题似乎是混合ES6样式函数的结果:

  getReply: (input, userId = null) => {   // No good

  getReply: function(input, userId = null) {  // OK

You can find the list of what ES6 features are currently supported by Node here . 您可以在此处找到Node当前支持的ES6功能列表。 As it stands, it doesn't look like default paremeters are implemented, or at least not fully. 就目前而言,它看起来不像默认的参数,或者至少不完全。

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

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