当我执行代码时:
console.log(Function.prototype);
它返回:
function Empty() {}
(至少在 Chrome 中)
这到底是为什么?我的印象是原型(prototype)几乎总是直接的对象文字,而且我检查过的几乎所有其他地方似乎都是这种情况。我很好奇为什么 Function.prototype 解析为不同的东西。
最佳答案
因为这是 ECMAScript 5 所需要的。
15.3.4 Properties of the Function Prototype Object
The
Function
prototype object is itself a Function object (its[[Class]]
is "Function") that, when invoked, accepts any arguments and returnsundefined
.
大多数(或全部?)其他 native 构造函数都将原型(prototype)定义为所生成的相同类型的对象。
考虑到原型(prototype)对象保存该类型的方法,因此在该对象上调用这些方法时应该正常运行是有意义的。
关于javascript - 为什么 Function.prototype 解析为函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14930390/