ECMAScript中的VariableStatement语义

okj*_*soo 5 javascript

生产VariableStatement:

var VariableDeclarationList ; 
Run Code Online (Sandbox Code Playgroud)

评估如下:

  1. 评估VariableDeclarationList.
  2. 返回(normal, empty, empty).

我想知道正常和空洞的含义.

CMS*_*CMS 7

ECMAScript描述了一个内部类型来解释语句的行为,它被称为完成规范类型.

完成类型的值是三元组的形式(type, value, target),其中:

  • type可以是normal,break,continue,return,或throw.
  • value可以是任何语言价值或empty.
  • target可以是任何Identifierempty.

在这种情况下VariableStatement,返回的完成没有可观察到的影响,它是正常完成,因为不修改控制流.

返回正常完成的其他语句是例如空语句,空语句,ExpressionStatement,语句(当没有附加调试器时)等等...Blockdebugger

A FunctionDeclaration(不是声明,但是a SourceElement)也返回(normal, empty, empty)完成,这就是为什么例如:

eval("function f(){}"); // returns undefined
Run Code Online (Sandbox Code Playgroud)

执行代码后的eval函数检查完成结果,如果类型normal和值是empty,则显式生成undefined(参见第7步eval),而:

eval("(function f(){})"); // returns a function object
Run Code Online (Sandbox Code Playgroud)

在那里括号构建一个PrimaryExpression,它是一个的一部分ExpressionStatement,这个语句返回完成(normal, GetValue(exprRef), empty),其中expRef将是值的FunctionExpression.

如果完成,type如果normal知道以外也称为" 突然完成 ".

例如:

function foo() {
  return 5;
}
foo();
Run Code Online (Sandbox Code Playgroud)

return内部的声明foo将产生一个看起来像的完成(return, 4, empty).

target三元组中的值仅用于breakcontinue,用于引用a的标识符LabelledStatement,例如:

foo: while(true) {
  while(true) {
    break foo;
  }
}
Run Code Online (Sandbox Code Playgroud)

上述break陈述的完成结果将是(break, empty, foo),因为控制流程whilefoo标签的水平上从第二个内部转移到外部.

你可以看到这是如何内部类型使用的详细信息,在执行所有其它语句非本地控制的转让为break,continue,returnthrow.