window.hasOwnProperty('innerHeight')在Firefox中返回false
window.hasOwnProperty('innerHeight') returns false in Firefox
在Firefox上运行的单元测试中,我遇到了一个奇怪的问题,在窗口对象上stub出innerHeight属性。
window.hasOwnProperty('innerHeight')
返回false
(仅在firefox中),这是根据https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN [docs] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)所期望的。然而,定义innerHeight属性的对象是什么?
这失败了(因为没有一个原型)的窗口属性?
window.prototype.hasOwnProperty('innerHeight');
我想知道的主要原因是在测试期间存根属性在chrome中工作,但在firefox中失败,因为firefox报告此属性不属于窗口对象。那么它属于什么物体呢?
prototype
属性属于Window
构造函数。但我会按照adeneo的建议使用'innerHeight' in window
,因为这会检查window
对象及其原型链。
相关文章:
- 如果 a 为 false,则 if(a) === if(false)
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 为什么这在IE中的工作方式与在Firefox中不同
- 如何将localStorage值设置为false
- JS可以在Chrome中工作,但不能在Firefox中工作
- createElement("a") - FireFox JavaScript
- 为什么javascript:void(0)在Firefox中不起作用
- Facebook登录按钮没有'不能在Firefox上工作
- jpm的默认Firefox路径没有'不起作用
- JavaScript-切换“;全部检查”;复选框true/false
- 为什么这个表达式在 Firefox/Chrome 中返回 true,而在 IE 中返回 false
- event.returnvalue=false 在 Firefox 中不起作用
- e.preventDefault() 并返回 false 在 Firefox 中不起作用
- Durandaljs 路由器重新加载页面,而不考虑 Firefox 中的“trigger: false”参数
- 当返回false;时,Javascript AJAX调用在firefox中失败;
- window.hasOwnProperty('innerHeight')在Firefox中返回false
- 为什么false++在Firefox中产生SyntaxError而在Chrome中产生ReferenceError ?
- 在Firefox中,click()设置后不运行复选框.Disabled = false
- 为什么Firefox 5在onsubmit = false的时候用外部javascript发送表单给服务器?
- 美元.ajax async:false不能在IE和Firefox中工作,在Chrome/Safari中工作