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.
有名字的函数表达式的名字
_a
只在定义的函数体内有效,外面无效我们把有名字的匿名函数表达式中的函数体称为内联函数,而函数名
_a
只能在这个内联函数的作用域内使用。ps:为什么叫内联函数,因为如果叫
命名匿名函数表达式
那特么太别扭了。console.log(_a);
应该改为console.log(a);
根据ECMA-262的说明,函数表达式里面_a可以在函数体内使用,但是在函数外引用不到。
但是,如果写出这样:
就没有问题了。因为此时是函数声明,不是函数表达式了。
所以,此问题重点是分清函数声明和函数表达式的区别。