Why is window not identical to window.self in Internet Explorer?

后端 未结 2 2015
有刺的猬
有刺的猬 2020-12-03 13:17

There\'s a convoluted backstory involving how I came across this, but why is the self property not exactly equal to the window itself?

In Safari and Fir

2条回答
  •  -上瘾入骨i
    2020-12-03 13:55

    Nice question. It does it with document and document.parentWindow too:

    window == document; // true
    window === document; // false
    
    window == document.parentWindow; // true
    window === document.parentWindow; // false
    

    The big wtf for me though is:

    window == document; // true
    document == window; // false
    

    You can swap out window with this in any of the above examples (and stay in the global context) with the same results. It makes the == operator even more suspect.

    Why it behaves this way is so beyond me.

提交回复
热议问题