最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js es6 class support - Stack Overflow

programmeradmin1浏览0评论

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

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

Share edited Sep 16, 2015 at 12:59 adnan kamili asked Sep 16, 2015 at 12:41 adnan kamiliadnan kamili 9,4959 gold badges75 silver badges134 bronze badges 2
  • I have used class without any flag – intekhab Commented Sep 16, 2015 at 12:44
  • @intekhab Node runs something called "magic mode" where it catches syntax errors in the REPL and tries to eval them with strict mode. – Benjamin Gruenbaum Commented Sep 16, 2015 at 12:45
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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

发布评论

评论列表(0)

  1. 暂无评论