update:
for( i in window)if(i=='onhashchange')console.log(i, window[i]); //prints onchangechange undefined
on browser where onhashchange event is supported I have
'onhashchange' in window; //returns true
window['onhashchange']; //returns false
window.onhashchange; //returns false;
why does the former returns true and the rest returns false?
I think with help of the first operation you just check if such an event is in window object, so it returns true. Two other tell you if such a handler is implemented, and there is no implementation yet you get false.
Can you check the following:
yea, anyway it will return true now, because we have defined that variable… So most probably
just checks if browser supports it
just checks if handler already implemented
PS. Also you can be interesting in Javascript IN operator compatibility, here @Andy E wrote:
UPDATE: to see difference between “x in window” and “window.x” (which is equal to window[‘x’]), take a look at the following script and its output:
UPDATE2: Detecting event support without browser sniffing – this article shows how to make event detection cross browser (because “event in window” does not work in Mozilla; this article also answers why it is so)