在Chrome中,函數Empty(){}在哪裏?
(function(){}).__proto__
是
function Empty() {}
,所以我本來期望
new Function();
是function Empty() {}
,而是它是function anonymous() {}
。
我在哪裏可以找到function Empty() {}
?它在Function
還是Object
某處?
在Chrome中,函數Empty(){}在哪裏?
(function(){}).__proto__
是
function Empty() {}
,所以我本來期望
new Function();
是function Empty() {}
,而是它是function anonymous() {}
。
我在哪裏可以找到function Empty() {}
?它在Function
還是Object
某處?
這些名稱並不意味着您可以使用這些標識符訪問它們。
至於功能的原型,其名稱是set at startup。該功能已被設置爲名稱,但除了.name
和.toString()
外,它沒有任何用途。
至於new Function()
實例,名稱僅爲printed for .toString()
。所以.name
仍然是空字符串。再次,它沒有太多的目的。
空函數對象(名稱爲Empty
)是Function
的原型。
Function.prototype.toString() === "function Empty() {}"
Object.getPrototypeOf(new Function()).toString() === "function Empty() {}"
Empty是Function的原型的名稱。從Chrome控制檯:
dir(Function)
function Function() { [native code] }
arguments: null
caller: null
length: 1
name: "Function"
prototype: function Empty() {}
__proto__: function Empty() {}
apply: function apply() { [native code] }
arguments: null
bind: function bind() { [native code] }
call: function call() { [native code] }
caller: null
constructor: function Function() { [native code] }
length: 0
name: "Empty"
toString: function toString() { [native code] }
__proto__: Object
謝謝。那麼函數anonymous(){}'呢? – Randomblue
@Randomblue'new Function()。toString()'會給你。 – xdazz