?um/p1-90`如果
无论控制以何种方式离开
eval 函数的调用都返回值 1:
eval("1;;;;;")
eval("1;{}")
eval("1;var a;")
The abstract operation BlockDeclarationInstantiation takes arguments code (一个 Parse Node) and env (一个
当对一个
被调用时它执行以下步骤:
let 和 const 声明定义的是作用域限于当前运行let 声明中
的某个
一条const 声明中。
var 语句声明的是作用域限于当前运行
如果某个
The syntax-directed operation PropertyBindingInitialization takes arguments value (一个
The syntax-directed operation RestBindingInitialization takes arguments value (一个
The syntax-directed operation KeyedBindingInitialization takes arguments value (一个
It is defined piecewise over the following productions:
function 或 class 开头,因为那会使它与 async function 开头,因为那会使它与
let [ 开头,因为那会使它与一
个 let
if 语句else] 这一前瞻限制以通常方式解决了经典的“悬空 else”问题。也就是说,当关联哪个 if 在其他方面仍然有歧义时,else 会与候选 if 中最近的(最内层的)那个相关联。
仅在实现了
The abstract operation LoopContinues takes arguments completion (一个
在
The syntax-directed operation LoopEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
do-while 语句
仅在实现了
The syntax-directed operation DoWhileLoopEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
while 语句
仅在实现了
The syntax-directed operation WhileLoopEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
for 语句
仅在实现了
The syntax-directed operation ForLoopEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
The abstract operation ForBodyEvaluation takes arguments test (一个
The abstract operation CreatePerIterationEnvironment takes argument perIterationBindings (一个 String 列表) and returns 要么是一个
for-in、for-of 和 for-await-of 语句
本节由附录
仅在实现了
The syntax-directed operation IsDestructuring takes no arguments and returns 一个 Boolean. It is defined piecewise over the following productions:
本节由附录
The syntax-directed operation ForDeclarationBindingInitialization takes arguments value (一个
The syntax-directed operation ForDeclarationBindingInstantiation takes argument environment (一个
The syntax-directed operation ForInOfLoopEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
本节由附录
The abstract operation ForIn/OfHeadEvaluation takes arguments uninitializedBoundNames (一个 String 列表), expr (一个
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs (一个 Parse Node), stmt (一个
The abstract operation EnumerateObjectProperties takes argument obj (一个 Object) and returns 一个迭代器对象. It performs the following steps when called:
next 方法会遍历 obj 的所有可枚举属性中值为 String 的键。该迭代器对象永远不能被 ECMAScript 代码直接访问。枚举属性的机制与顺序未被规定,但必须符合下方规定的规则。
该迭代器的 throw 和 return 方法为 next 方法会处理对象属性,以判定该next 方法处理之前就已被删除的属性会被忽略。如果在枚举期间向
目标对象新增属性,则不能保证这些新加属性会在当前激next 方法返回一次。
对目标对象属性的枚举还包括递归枚举其原型、原型的原型,以此类推;但如果某
个原型上的属性与已被迭代器 next 方法处理过的某个属性同名,则不会处理该原
型属性。在判断某个原型对象的属性是否已被处理时,不考虑 [[Enumerable]] 特
性的值。原型对象的可枚举
此外,如果 obj 及其原型链上的任何对象都不是
ECMAScript 实现不要求直接实现
以下是一个符合这些规则的 ECMAScript 生成器函数的信息性定义:
function* EnumerateObjectProperties(obj) {
const visited = new Set();
for (const key of Reflect.ownKeys(obj)) {
if (typeof key === "symbol") continue;
const desc = Reflect.getOwnPropertyDescriptor(obj, key);
if (desc) {
visited.add(key);
if (desc.enumerable) yield key;
}
}
const proto = Reflect.getPrototypeOf(obj);
if (proto === null) return;
for (const protoKey of EnumerateObjectProperties(proto)) {
if (!visited.has(protoKey)) yield protoKey;
}
}
For-In 迭代器
是一种对象,它表示对某个特定对象进行的一次特定迭代。For-In 迭代器对象永远
不能被 ECMAScript 代码直接访问;它们的存在仅用于说明
The abstract operation CreateForInIterator takes argument object (一个 Object) and returns 一个
%ForInIteratorPrototype% 对象:
| 内部槽 | 类型 | 描述 |
|---|---|---|
| [[Object]] | 一个 Object | 其属性正在被迭代的 Object 值。 |
| [[ObjectWasVisited]] | 一个 Boolean |
如果迭代器已经对 [[Object]] 调用了 [[OwnPropertyKeys]],
则为 |
| [[VisitedKeys]] | 一个 String 列表 | 到目前为止该迭代器已经发出的值。 |
| [[RemainingKeys]] | 一个 String 列表 |
在开始迭代其原型的属性之前(如果其原型不为 |
continue 语句static
初始化块边界)嵌套在一个 break 语句static
初始化块边界)嵌套在一个 return 语句
return 语句会使函数停止执行,并且在大多数情况下会向调用者返回一个值。
如果省略 return 语句实际上不一定真的向
调用者返回一个值。例如,在 try 块中,return 语句的 finally 块求值期间被另一个
with 语句
with 语句会为一个计算得出的对象向当前运行
仅在实现了
switch 语句如果
The syntax-directed operation CaseBlockEvaluation takes argument input (一个
The abstract operation CaseClauseIsSelected takes arguments constructor (一个
该操作不会执行 constructor 的
无论控制如何离开
break 和
continue 语句一起使用。ECMAScript 没有 goto 语句。一个
The abstract operation IsLabelledFunction takes argument stmt (一个
The syntax-directed operation LabelledEvaluation takes argument labelSet (一个 String 列表) and returns 要么是一个
throw 语句try 语句
try 语句包围了一段可能发生异常情况的代码块,例如运行时错误或一条
throw 语句。catch 子句提供异常处理代码。当 catch 子句捕获一个异常时,
它的
The syntax-directed operation CatchClauseEvaluation takes argument thrownValue (一个
无论控制如何离开
debugger 语句
对