javascript - nodejs error on es6 class constructor with default parameter value -


i run simple es6 class code following:

'use strict'; class polygon {   constructor(height=44, width=55) { //class constructor     this.name = 'polygon';     this.height = height;     this.width = width;   }    sayname() { //class method     console.log('hi, a', this.name + '.');    } }  class square extends polygon {   constructor(length) {     super(length, length); //call parent method super     this.name = 'square';   }    area() { //calculated attribute getter     return this.height * this.width;   } }  let s = new square();   s.sayname();  console.log(s.area); 

it running ok on chrome console. running errors on nodejs(4.x, 5.x) following:

constructor(height=44, width=55) { //class constructor                       ^    syntaxerror: unexpected token =   @ exports.runinthiscontext (vm.js:53:16)   @ module._compile (module.js:387:25)   @ object.module._extensions..js (module.js:422:10)   @ module.load (module.js:357:32)   @ function.module._load (module.js:314:12)   @ function.module.runmain (module.js:447:10)   @ startup (node.js:148:18)   @ node.js:405:3 

i think es6 support default parameters function, , chrome , node.js run v8 engine, why give out diff answer,...

this in progress feature in 5.x can activated flag --harmony_default_parameters:

$ node -v  v5.0.0 $ node --harmony_default_parameters  script.js 

to see list of in progress flags in node version:

node --v8-options | grep "in progress" 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -