问题描述
为什么引擎报告函数 Empty()
是 JavaScript 中原生 Function
函数的原型,但该函数本身是未定义的(从用户的角度来看)看法)?
Why does the engine report that the function Empty()
is the prototype of the native Function
function in JavaScript, but that function is itself undefined (from the user's point of view)?
Function.prototype; // function Empty()
Function.__proto__; // function Empty()
Function.constructor; // function Function()
Empty(); // Uncaught ReferenceError: Empty is not defined
Object.prototype; // Object {}
Object.__proto__; // function Empty()
Object.constructor; // function Function()
Number.prototype; // Number {[[PrimitiveValue]]: 0}
Number.__proto__; // function Empty()
Number.constructor; // function Function()
String.prototype; // String {length: 0, [[PrimitiveValue]]: ""}
String.__proto__; // function Empty()
String.constructor; // function Function()
Boolean.prototype; // {[[PrimitiveValue]]: false}
Boolean.__proto__; // function Empty()
Boolean.constructor; // function Function()
为什么不将所有对 Empty()
的引用都指向 null
或一些空对象?
Why not point all of those references to Empty()
to null
or some empty object?
推荐答案
因为 Function.prototype
对象 基本上是一个空的功能.
Because the Function.prototype
object is basically an empty function.
那个函数本身是未定义的(从用户的角度来看)?
我没明白你的意思,Function.prototype
已经很明确了.如果您的意思是标识符 Empty
,则没有理由仅仅因为它用于 函数名称.
I don't see what you mean, Function.prototype
is pretty defined. If you mean the identifier Empty
, there's no reason it would be a global variable just because it's used for the name of a function.
为什么不将所有对 Empty() 的引用都指向 null?
因为那会破坏继承.
还是一些空物体?
它是一个空对象——一个空的函数对象.为什么不是普通对象?因为规范是这么说的.
It is an empty object - an empty function object. Why not a plain object? Because the spec says so.
这篇关于JavaScript 中的 Empty 函数是什么,为什么它是未定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!