[英]Why performance.hasOwnProperty('getEntries') returns false while typeof performance.getEntries returns function?
Window property performance has a function call getEntries to retrieve all performance entries. Window 属性性能有一个 function 调用 getEntries 来检索所有性能条目。 which works on all modern browsers but doesn't work on a few older browsers like Safari 10. To add a check of working browsers....
它适用于所有现代浏览器,但不适用于 Safari 10 等一些较旧的浏览器。添加对工作浏览器的检查....
If we try to verify using performance.hasOwnProperty('getEntries')
, It always return false.如果我们尝试使用
performance.hasOwnProperty('getEntries')
进行验证,它总是返回 false。 But it works if use typeof performance.getEntries === 'function'
.但是如果使用
typeof performance.getEntries === 'function'
就可以了。
Would like to understand the logic behind it.想了解其背后的逻辑。
performance does not has own property “getEntries”, this property is owned by prototype of Performance, which is the constructor of performance object. performance 没有自己的属性“getEntries”,该属性由 Performance 的原型所有,它是性能 object 的构造函数。
when you use performance.getEntries(), actually Performance.prototype.getEntries() is called.当您使用 performance.getEntries() 时,实际上会调用 Performance.prototype.getEntries()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.