Node.js中的函数构造函数是什么?
在浏览器(至lesschrome)函数是Function
实例
setTimeout instanceof Function // true
但是在节点中,它们不是
setTimeout instanceof Function // false
那么setTimeout
的构造Function
什么Function
呢?
看起来构造函数是Function
,但是来自另一个领域的Function
。
如果你运行这个代码
console.log(Object.getOwnPropertyNames(setTimeout.constructor.prototype));
你会得到一个典型的Function.prototype
方法,比如call
, apply
和bind
。
所以我猜这有点类似于当你从iframe借用setTimeout
时候在web浏览器中发生的事情:
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