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

What is the function constructor in Node.js?

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

的实例
setTimeout instanceof Function
// true

但是在节点中,它们不是

setTimeout instanceof Function
// false

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

构造器好像是Function,不过是异界的

如果你运行这个代码

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

你得到一个数组,其中包含典型的 Function.prototype 方法,例如 callapplybind

所以我想这有点类似于当您从 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