admin管理员组文章数量:1395752
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
-
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
2 Answers
Reset to default 4Well, 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.
本文标签: javascriptNodejs es6 class supportStack Overflow
版权声明:本文标题:javascript - Node.js es6 class support - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744648968a2617570.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论