所以我有一个由eventemitter3
节点模块创建的对象。事件发射器具有属性_events
,当我在Chrome检查器中查看它时,会显示Events {}
。但是,当我尝试查看其构造函数(temp1.constructor
)时,我得到undefined
!在MDN(here)的描述中,它说“所有对象都有constructor
属性”,但我在Chrome控制台中有一个明确的反例(我也在Firefox中试过这个,所以它是不太可能是V8的问题。)
我可以在the eventemitter3 source中看到定义Events
类的以下行:
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
所以我认为他们试图摆脱constructor
财产是有道理的,但是:
"Events"
?