2016-11-05 63 views
11

在瀏覽器(Chrome至少)功能然而,在節點的FunctionNode.js中的函數構造函數是什麼?

setTimeout instanceof Function 
// true 

的情況下,他們沒有

setTimeout instanceof Function 
// false 

那麼,什麼是setTimeout的構造函數如果不是Function

+0

構造** **是一個功能。嘗試'typeof setTimeout.constructor' – undefined

+0

我知道它的* a *函數,我在問哪個函數 –

+0

使用節點版本6.5.0,'Function.prototype.check = true; console.log(setTimeout.check);'爲我打印真品 – Sergeon

回答

3

看起來構造函數是Function,但是來自另一個領域的構造函數。

如果你運行這段代碼

console.log(Object.getOwnPropertyNames(setTimeout.constructor.prototype)); 

你得到的典型Function.prototype方法,如callapplybind的數組。

所以我想這有點類似於Web瀏覽器會發生什麼,當你從一個iframe借setTimeout

var iframe = document.createElement('iframe'); 
document.body.appendChild(iframe); 
var win = iframe.contentWindow; 
console.log(win.setTimeout instanceof Function);  // false 
console.log(win.setTimeout instanceof win.Function); // true 
+0

不知道他們爲什麼要這樣做。 – Oriol

相關問題