简体   繁体   English

为什么 performance.hasOwnProperty('getEntries') 返回 false 而 typeof performance.getEntries 返回 function?

[英]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.

相关问题 window.performance.getEntries() 是什么意思? - What does window.performance.getEntries() mean? 为什么`getOwnPropertyDescriptor`返回一个值,而`hasOwnProperty`返回`false`? - Why does `getOwnPropertyDescriptor` return a value, while `hasOwnProperty` returns `false`? hasOwnProperty在FF中返回false - hasOwnProperty returns false in FF 为什么 hasOwnProperty 在构造函数上返回 false,但在未实例化函数的情况下访问字符串属性时返回 true - Why hasOwnProperty returns false on a constructor function but string property returns true when accessed without instantiating the function 为什么`typeof false || undefined`返回“布尔值” - Why does `typeof false || undefined` returns “boolean” javascript hasOwnProperty返回true而不是false? - javascript hasOwnProperty returns true instead of false? window.hasOwnProperty('innerHeight')在Firefox中返回false - window.hasOwnProperty('innerHeight') returns false in Firefox hasOwnProperty 总是使用 Typescript 返回 false - hasOwnProperty always returns false using Typescript hasOwnProperty('getTime')在日期对象上返回false - hasOwnProperty('getTime') returns false on date object object.style.hasOwnProperty('MozTransform')返回false? - object.style.hasOwnProperty('MozTransform') returns false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM