如果你不能用你给它们的名字真正引用它们,那么命名函数表达式有什么意义呢?
var f = function g() {
console.log("test");
};
g(); // ReferenceError: g is not defined
Run Code Online (Sandbox Code Playgroud)
Roc*_*mat 11
哦,但你可以用这个名字来引用它们.这些名称只存在于函数的范围内.
var f = function g() {
// In here, you can use `g` (or `f`) to reference the function
return typeof g;
};
console.log( typeof g );
// It only exists as `f` here
console.log( f() );Run Code Online (Sandbox Code Playgroud)
DOCS:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function#Named_function_expression
| 归档时间: |
|
| 查看次数: |
238 次 |
| 最近记录: |