首页 > 解决方案 > 为什么 performance.hasOwnProperty('getEntries') 返回 false 而 typeof performance.getEntries 返回函数?

问题描述

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

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

想了解其背后的逻辑。

标签: javascriptperformancewindowtypeofhasownproperty

解决方案


performance 没有自己的属性“getEntries”,该属性由 Performance 的原型所有,它是性能对象的构造函数。

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


推荐阅读