javascript - 为什么 performance.hasOwnProperty('getEntries') 返回 false 而 typeof performance.getEntries 返回函数?
问题描述
窗口属性性能有一个函数调用 getEntries 来检索所有性能条目。它适用于所有现代浏览器,但不适用于一些较旧的浏览器,如 Safari 10。添加对工作浏览器的检查....
如果我们尝试使用 进行验证performance.hasOwnProperty('getEntries')
,它总是返回 false。但如果使用 typeof performance.getEntries === 'function'
.
想了解其背后的逻辑。
解决方案
performance 没有自己的属性“getEntries”,该属性由 Performance 的原型所有,它是性能对象的构造函数。
当您使用 performance.getEntries() 时,实际上会调用 Performance.prototype.getEntries()。
推荐阅读
- reactjs - React + TypeScript broke overnight - "All declarations of 'value' must have identical modifiers." in node_modules/@types/es6-shim/index.d.ts
- c# - Trying to move data binding from MainWindow.xaml.cs to another ViewModel module
- url-routing - 如何删除 SilverStripe 4 中其他供应商模块添加的路由?
- assembly - 简单的 hello world exec 是 10 KB
- oauth - Google 登录 JavaScript 客户端无法在 PWA 应用上运行
- html - 插入浮动图像的项目符号点,但应该在它旁边
- azure - 将 Azure VM 迁移到其他位置
- javascript - 为什么我的完整 HTML 示例页面为什么不起作用?
- python - Python全局变量不适用于新文件的用户定义函数
- java - 为智能手机的具体模型选择布局参数