var a = function _a() {
}
console.log(_a);
为什么这里 log的时候 会报错???
我们把有名字的匿名函数表达式中的函数体称为内联函数,而函数名 _a
只能在这个内联函数的作用域内使用。
ps:为什么叫内联函数,因为如果叫命名匿名函数表达式
那特么太别扭了。
The BindingIdentifier in a FunctionExpression can be referenced from inside the FunctionExpression's FunctionBody to allow the function to call itself recursively. However, unlike in a FunctionDeclaration, the BindingIdentifier in a FunctionExpression cannot be referenced from and does not affect the scope enclosing the FunctionExpression.
根据ECMA-262的说明,函数表达式里面_a可以在函数体内使用,但是在函数外引用不到。
但是,如果写出这样:
function _a() {
}
console.log(_a);
就没有问题了。因为此时是函数声明,不是函数表达式了。
所以,此问题重点是分清函数声明和函数表达式的区别。
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
有名字的函数表达式的名字
_a
只在定义的函数体内有效,外面无效