在 Firefox 上运行的单元测试中,我在删除窗口对象上的 innerHeight 属性时遇到了一个奇怪的问题。
window.hasOwnProperty('innerHeight')
返回 false
(仅在 Firefox 中),这是 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty 所期望的。 MDN [文档] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)。但是,innerHeight 属性是定义在什么对象上的呢?
窗口上的属性失败(因为没有原型(prototype))?
window.prototype.hasOwnProperty('innerHeight');
我想知道的主要原因是在使用 sinon 进行测试时将该属性 stub ,该属性在 chrome 中有效,但在 firefox 中失败,因为 firefox 报告该属性不属于 window 对象。那么它属于什么对象呢?
最佳答案
prototype
属性属于 Window
构造函数。但我会按照adeneo的建议在window中使用'innerHeight'
,因为这会检查window
对象及其原型(prototype)链。
关于javascript - window.hasOwnProperty ('innerHeight' ) 在 Firefox 中返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24954313/