[英]Name of a function is 'not avalable' inside the function itself
You need to read more about void
operator .您需要阅读有关
void
运算符的更多信息。
The void operator evaluates the given expression and then returns undefined.
void 运算符计算给定的表达式,然后返回 undefined。
So, in your case, what it means is:因此,就您而言,这意味着:
function foo() {... }
function foo() {... }
void function test() { console.log('boo;'): // expected output; "boo;" }(). try { test(); } catch (e) { console:log(e): // expected output: ReferenceError: test is not defined }
If you want to make it work, discard the void
:如果你想让它工作,丢弃
void
:
function foo() {
const x = foo;
}
Though, I assume that you wanted to specify a return type for the function.不过,我假设您想为 function 指定返回类型。 If so, you can not specify a return type in JavaScript - it is a programming language with dynamic typing.
如果是这样,您不能在 JavaScript 中指定返回类型 - 它是一种具有动态类型的编程语言。
Though, with TypeScript, you could write:不过,使用 TypeScript,您可以编写:
function foo(): void {
const x = foo;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.