为什么 performance.hasOwnProperty('getEntries') returns false 而 typeof performance.getEntries returns 函数?

Why performance.hasOwnProperty('getEntries') returns false while typeof performance.getEntries returns function?

Window 属性 性能有一个函数调用 getEntries 来检索所有性能条目。它适用于所有现代浏览器,但不适用于一些较旧的浏览器,如 Safari 10。要添加对工作浏览器的检查....

如果我们尝试使用 performance.hasOwnProperty('getEntries') 进行验证,它总是 return 错误。 但是如果使用 typeof performance.getEntries === 'function'.

它会起作用

想了解其背后的逻辑。

performance 没有自己的 属性 “getEntries”,这个 属性 属于 Performance 的原型,它是 performance 对象的构造函数。

当您使用 performance.getEntries() 时,实际上会调用 Performance.prototype.getEntries()。