update:
for( i in window)if(i=='onhashchange')console.log(i, window[i]); //prints onchangechange undefined
在支持 onhashchange 事件的浏览器上我有
'onhashchange' in window; //returns true
window['onhashchange']; //returns false
window.onhashchange; //returns false;
为什么前者返回 true,其余返回 false?
难道仅仅是因为window
对象有一个属性称为onhashchange
,但该房产目前的价值是null
因此被认为是假的?
var a = { 'foo': null }
console.log('foo' in a) // true
console.log(a.foo) // null
console.log(!!a.foo) // false
……哪里!!
是一个双重否定,是将值转换为真/假的技巧。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)