ECMAScript 规范详细介绍了当控制进入 function within a function 的执行上下文时会发生什么情况。 。
function foo() {
function bar() {
}
bar(); // Control will be given to the bar function. Details specified by spec
}
还有一个关于当控制enters global code时会发生什么的解释。 .
<script>
// Entering global code! Details specified by spec
</script>
但是,没有任何内容指定输入对全局代码中定义的函数的控制权时会发生什么。
<script>
function foo() {
}
foo(); // Calling a function defined in the global environment...not specified by spec
</script>
编辑:这对我来说很重要,因为我很好奇全局代码调用的函数的内部 [[Scope]] 属性是什么。我假设它将是全局执行上下文的词法环境,但规范中没有指定这一点。
最佳答案
我认为您误解了这句话(来自 §10.4.3, Entering Function Code ):
The following steps are performed when control enters the execution context for function code contained in function object
F
, a caller providedthisArg
, and a caller providedargumentsList
[…]
并不意味着输入的函数必须包含在F
中,而是表示输入的代码包含在函数中>F
(您正在调用)。
[[Call]]
method当 calling a function 时使用不区分全局/局部声明或调用的函数。
关于javascript - ECMAScript 规范 v5 中缺少有关输入在全局作用域中声明的函数时会发生什么的详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15123595/