Node.js中的函数构造函数是什么?

Aak*_*des 11 javascript prototypal-inheritance node.js

在浏览器(至少chrome)函数是实例 Function

setTimeout instanceof Function
// true
Run Code Online (Sandbox Code Playgroud)

但是在节点中,它们不是

setTimeout instanceof Function
// false
Run Code Online (Sandbox Code Playgroud)

那么setTimeout如果不是Function什么构造函数呢?

Ori*_*iol 3

看起来构造函数是Function,但是来自另一个领域的构造函数。

如果你运行这段代码

console.log(Object.getOwnPropertyNames(setTimeout.constructor.prototype));
Run Code Online (Sandbox Code Playgroud)

你会得到一个带有,和Function.prototype等典型方法的数组。callapplybind

所以我想这有点类似于当你setTimeout从 iframe 借用时在网络浏览器中发生的情况:

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
Run Code Online (Sandbox Code Playgroud)