2016-11-05 159 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

相关问题