the specification的一部分for-of
语句包含以下行:
It is a Syntax Error if the BoundNames of ForDeclaration contains "let".
在我看来,这意味着你不能写:
for (var let of someObject) { /* ... */ }
但是你也会得到其他保留字的语法错误,例如:
for (var function of someObject) { /* ... */ }
或
for (let for of someObject) { /* ... */ }
明确一点,let
本身就是perfectly valid用于在此处声明 变量。
let
有什么特别之处,这意味着它在此处的规范中被挑出来了,还是我对这一行的解释不正确?
最佳答案
那是因为 let
正式不是 keyword :
In strict mode code,
let
andstatic
are treated as reserved keywords through static semantic restrictions (see 12.1.1, 13.3.1.1, 13.7.5.1, and 14.5.1) rather than the lexical grammar.
虽然我不能告诉你为什么他们决定这样做。
关于javascript - 为什么 let 在 for-of 规范中被挑出来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34317632/