Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

IE 10 以下 , setTimeout and setInterval 奇怪现象 #2

Open
caihuiji opened this issue May 24, 2015 · 1 comment
Open

IE 10 以下 , setTimeout and setInterval 奇怪现象 #2

caihuiji opened this issue May 24, 2015 · 1 comment
Labels

Comments

@caihuiji
Copy link
Member

  • IE10 以下版本中 setTimeout 为只读方法,无法篡改替换 , 而 window.setTimeout 是可以修改的
    qq 20150524233244
    所以,我们只对 window.setTimeout 进行切面处理。当然我们为了保证统一,也只对window.setInterval 进行了同样处理
  • IE6、IE7、IE8中window.setTimeout和window.setInterval为Object,非Function,没有继承apply和call方法
    所以不能对 window.setTimeout 或 window.setInterval 像其他切面处理那样直接进行 apply 。
@caihuiji caihuiji changed the title IE 9 以下 , setTimeout and setInterval 奇怪现象 IE 10 以下 , setTimeout and setInterval 奇怪现象 May 24, 2015
@caihuiji caihuiji mentioned this issue May 25, 2015
@loskael
Copy link
Member

loskael commented Oct 9, 2015

参考 imweb/tryjs#4
在浏览器环境下 window.setTimeout === setTimeout;
在 IE6-9 下, setTimeout 是只读的, window 是可写的, 重写 window.setTimeout 将会导致 以上等式不成立
以下代码结果为上述浏览器下的测试结果

    typeof window.setTimeout; // object
    window.setTimeout === setTimeout; // true

    var temp = window.setTimeout;
    window.setTimeout = function(fn, delay){
        return temp(fn, delay);
    };

    typeof window.setTimeout; // function
    window.setTimeout === setTimeout; // false
    temp === setTimeout; // true

    typeof window.xxx; // undefined
    window.xxx = 'hehe';
    typeof window.xxx; // string
    window.xxx; // hehe
    xxx; // hehe

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants