node中的let

    node.js

手上node.js项目用pm2管理node进程。

重启服务,pm2 stop app停止进程,再用pm2 start ecosystem.json启动。

预订的6个进程并未全部开启,并且cpu占用奇高。查看pm2错误日志,里面错误如下:
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

修改的代码恰好用到let关键字,至此,错误排查完毕。

查询node.js相关信息,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
所有的 ECMAScript 2015 (ES6) 功能将被分为三个部分 shipping,staged 和 in progress:

所有 shipping:在 V8 引擎中认为是稳定的,转变成 Node.js 默认,并且 不会 需要任何运行时标记。
Staged:这些是将要完成的特性,并且在 V8 团队看来并不一定稳定,需要一个 --harmony 标记。
In progress:这些特性可以通过各自单独的 harmony 标记被激活使用。除非为了测试用途,否则绝不鼓励这样做。值得注意的是这些标记是借由 V8 引擎公开,将来或许会有潜在的变化而不会有任何免责声明或者协议。

『shipping』 已经开启的 ES6 特性
目前默认开启的 ES6 特性如下:

Block scoping
let (strict mode only)
const
function-in-blocks (strict mode only [1])
Classes (strict mode only)
Collections
Map
WeakMap
Set
WeakSet
Typed arrays
Generators
Binary and Octal literals
Object literal extensions (shorthand properties and methods)
Promises
New String methods
Symbols
Template strings
Arrow Functions
new.target [2]
Object.assign
Spread operator [2]

所以,在非严格模式下的node.js中没法用let关键字

02 Nov 2018

page PV:  ・  site PV:  ・  site UV: