Why does Twitter redefine window.setTimeout and window.setInterval?

后端 未结 1 433
野性不改
野性不改 2021-01-03 00:20

I was studying the Twitter source code, and I came across the following snippet:

   window.setTimeout=window.setTimeout;window.setInterval=window.setInterval         


        
相关标签:
1条回答
  • This is a technique to replace setTimeout and setInterval functions globally in a cross-browser fashion.

    window.setTimeout, when used as an lvalue (on the left side of the assignment), does not walk the prototype chain, but on the right side, it does. So this will always pull a property out of the prototype chain and put it right on the object.

    See http://www.adequatelygood.com/2011/4/Replacing-setTimeout-Globally.

    0 讨论(0)
提交回复
热议问题