[英]Typeof for javascript function
When I declare a function like this: 当我声明这样的函数时:
function x() { return 123 };
Then: 然后:
typeof x; //return "function"
typeof x(); //return "number"
That's ok, but once I create a variable like this: 没关系,但是一旦我创建了这样的变量:
var y = function x() { return 123 };
It becomes: 它成为了:
typeof y; //return "function"
typeof y(); //return "number"
typeof x; //return "undefined"
typeof x(); //return error
Why does x lose his function? 为什么x失去功能? Please helpp
请帮忙
Why does x lose his function?
为什么x失去功能?
A function declaration creates a variable of the same name in the current scope. 函数声明会在当前作用域中创建一个具有相同名称的变量。
A named function expression does not (except in certain older versions of Internet Explorer, which is a bug). 命名函数表达式没有(在某些较旧的Internet Explorer版本中,这是一个错误)。
That's just how function expressions are supposed to work. 这就是函数表达式应该如何工作的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.