什么是JavaScript中的函数Empty()? [英] What is - function Empty() - in javascript ?
问题描述
我具有此功能:
函数fff(){}
哪个是 function
,它是 Function构造函数
所以 fff .__ proto __
应该告诉我: function Function(){[native code]}
但事实并非如此.
它显示: functionEmpty(){}
我只能在 __ proto __
的 constructor
属性中看到 function Function(){[native code]}
It is only at the constructor
property of __proto__
that I see function Function() { [native code] }
问题:
这是什么 functionEmpty(){}
function
以及为什么 fff .__ proto __
不会显示给我: function Function(){[native code]}
?
What is this function Empty() {}
function
and why fff.__proto__
won't show me : function Function() { [native code] }
?
nb我知道 __ proto __
是查找链中用于解析方法等的实际对象. prototype
是用于构建的对象>使用 new
创建对象时 __ proto __
.
nb
I know that __proto__
is the actual object that is used in the lookup chain to resolve methods, etc. prototype
is the object that is used to build __proto__
when you create an object with new
.
但是再说一次:函数 fff
是通过更新 Function构造函数在后台实例化的函数.
...如此吗?
But again : function fff
is a function which is instantiated behind the scenes by newing Function constructor.
...so ?
推荐答案
您误会了 __ proto __
.
__ proto __
返回对象继承的原型值;不是其构造函数.
__proto__
returns the prototype value that the object inherits; not its constructor.
所有函数(包括 Function
本身)都继承 Function.prototype
.
因此, Function .__ proto__ === Function.prototype
为true.
在规范的 15.3.4 部分中指定了此对象:
All functions (including Function
itself) inherit Function.prototype
.
Thus, Function.__proto__ === Function.prototype
is true.
This object is specified in section 15.3.4 of the spec:
Function原型对象本身就是一个Function对象(其
[[Class]]
是"Function"
),该对象在被调用时将接受任何参数并返回未定义的
The Function prototype object is itself a Function object (its
[[Class]]
is"Function"
) that, when invoked, accepts any arguments and returns undefined.
另请参见
15.3.4.2 Function.prototype.toString()
返回函数的依赖实现的表示形式.此表示形式具有 FunctionDeclaration 的语法.特别要注意的是,在String表示中空格,行终止符和分号的使用和放置取决于实现.
15.3.4.2 Function.prototype.toString ( )
An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.
toString
函数不是通用的;如果此值不是Function对象,则抛出TypeError异常.因此,不能将其传递给其他类型的对象用作方法.
The toString
function is not generic; it throws a TypeError exception if its this value is not a Function object. Therefore, it cannot be transferred to other kinds of objects for use as a method.
这篇关于什么是JavaScript中的函数Empty()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!