Node.js:如何在V8引擎中启用non strict或ECMASCRIPT3?
我相信V8底层Node.js默认支持严格模式或ES5。
我们可以在V8引擎中启用非严格或ECMASCRIPT 3吗?
Chrome(V8)中几乎有100%的ES5function可用,请参阅兼容性表 。
但是一些开发人员(包括我)仍然对ES3感到满意,我们可以有这个select吗?
只是不要在你的代码中包含string"use strict"
。 V8支持严格模式,除非您告诉它(即遵循ES5规范),否则不会使用它。
比较以下脚本:
input:
foo = "Hello"; console.log(foo);
输出:
quentin@workstation:tmp # node test.js Hello
和
input:
"use strict"; foo = "Hello"; console.log(foo);
输出:
quentin@workstation:tmp # node test.js node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ ReferenceError: foo is not defined at Object.<anonymous> (/Users/quentin/tmp/test.js:2:5) at Module._compile (module.js:432:26) at Object..js (module.js:450:10) at Module.load (module.js:351:31) at Function._load (module.js:310:12) at Array.0 (module.js:470:10) at EventEmitter._tickCallback (node.js:192:40)