function(){}.__proto__ === Function.prototype
和 Function.prototype === function(){}.__proto__
得到不同的结果
Function.prototype === function(){}.__proto__
返回 true
。
function(){}.__proto__ === Function.prototype
返回一个错误:
VM2053:1 Uncaught SyntaxError: Function statements require a function name
最佳答案
因为函数声明必须有一个名字,而函数表达式则没有。来自 Immediately invoked function expression 上的维基页面,如果该行以 function
开头:
when the parser encounters the function keyword, it treats it as a function declaration (statement), and not as a function expression.
关于javascript - 为什么 function(){}.__proto__ === Function.prototype 和 Function.prototype === function(){}.__proto_ 返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57723700/