Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js es6 class support

Finally es6 classes have landed in Node.js v4.0.0. But the feature needs --use_strict option to be passed. e.g.

node --use_strict sampleClass.js

What does this --use_strict option signify? Has it anything to do with "use strict"; javascript directive.

Note: On Linux Classes worked in v0.12 too but not in Windows

Edit: If you want to omit --use_strict flag than use "use strict"; in js file

like image 687
adnan kamili Avatar asked Mar 14 '23 18:03

adnan kamili


2 Answers

Well, JS has a strict mode which slightly changes how scoping works as well as other small things. Generally, it should be preferred since the bodies of classes and modules are always in strict mode anyway.

Classes work both in strict and loose mode. However, the JavaScript engine Node runs only supports running classes in strict mode at the moment.

This is a limitation of V8 (the engine) and will be resolved in the future. Here is the bug tracking it.

like image 101
Benjamin Gruenbaum Avatar answered Mar 24 '23 06:03

Benjamin Gruenbaum


Starting from version 6, classes in NodeJS just work, so no --use_strict flag is required.

like image 38
jayarjo Avatar answered Mar 24 '23 06:03

jayarjo