Question about jQuery source == on window

泪湿孤枕 提交于 2019-12-20 02:05:10

问题


data: function( elem, name, data ) {
    if ( !jQuery.acceptData( elem ) ) {
        return;
    }
    elem = elem == window ? windowData : elem;

Copied directly from the jQuery source.

Why is it not safe to use elem === window?

Why does jQuery use type coercion on the window object?

It would appear that in IE there's an issue with top

top == window // true
top === window // false

回答1:


See here for why checking againts the window object with === is unsafe in IE.

I think the root cause is that IE is closely coupled with the Windows OS so you have various OS objects referenced through window and the equality check just dies. That and it just doesn't handled the global host object correctly.



来源:https://stackoverflow.com/questions/4847024/question-about-jquery-source-on-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!