Node: ES6 Default Parameters

Created on 26 Sep 2015  路  10Comments  路  Source: nodejs/node

Seems that node forgot to add default params to the todo =)

[rafael@rcepeda ~]$ node --v8-options | grep "in progress"
  --harmony_modules (enable "harmony modules" (in progress))
  --harmony_array_includes (enable "harmony Array.prototype.includes" (in progress))
  --harmony_regexps (enable "harmony regular expression extensions" (in progress))
  --harmony_proxies (enable "harmony proxies" (in progress))
  --harmony_sloppy (enable "harmony features in sloppy mode" (in progress))
  --harmony_unicode_regexps (enable "harmony unicode regexps" (in progress))
  --harmony_reflect (enable "harmony Reflect API" (in progress))
  --harmony_destructuring (enable "harmony destructuring" (in progress))
  --harmony_sharedarraybuffer (enable "harmony sharedarraybuffer" (in progress))
  --harmony_atomics (enable "harmony atomics" (in progress))
  --harmony_new_target (enable "harmony new.target" (in progress))

My error

function logEvent(message, isError = false) {
                                   ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

Does node plan to implement this? It is very helpful.

[rafael@rcepeda ~]$ node -v
v4.1.1
V8 Engine

Most helpful comment

@Krispomoho It's still behind --harmony_default_parameters in v5.x. It'll be enabled by default in v6.0.

All 10 comments

This isn't in our hands. JavaScript features are implemented by Chrome's v8 JavaScript engine, which we embed and use to run our js.

Please check here for the status of es6 features in chrome. :)

https://www.chromestatus.com/features

Awe okay, Thank you!

It's here now :)

node --harmony_default_parameters --eval "const t = function(i = 42) { return i }; console.log(t());"

> 42

I don't suggest using --harmony* flags -- those indicate a work in progress and may be broken or have terrible edge cases.

Agreed. Those are very much "use at your own risk." You'd be better off waiting for them to land in a stable version. If you absolutely MUST have them now, consider a transpiler.

I have used 'use strict', but still have this problem. My node version is v5.2.0

@Krispomoho It's still behind --harmony_default_parameters in v5.x. It'll be enabled by default in v6.0.

Just FYI, I tested with version 6.1 and the default parameters feature is working without the flag. You can use nvm to upgrade node.

Yes, these shipped in v6.0.0

IIRC they preform ok too: https://github.com/nodejs/node/commit/7dc1a87a7b2ac8be34aa1e74643766cdc90c82d4

I think core started using them.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstaleiny picture danielstaleiny  路  3Comments

Brekmister picture Brekmister  路  3Comments

akdor1154 picture akdor1154  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

addaleax picture addaleax  路  3Comments