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

↘锁芯ラ 提交于 2019-12-30 04:49:06

问题


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

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

Why does Twitter redefine these functions?

Edit: To see the code, go to any twitter user page, open the source of the page, and you will see that snippet in the second block of javascript.


回答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.



来源:https://stackoverflow.com/questions/8044433/why-does-twitter-redefine-window-settimeout-and-window-setinterval

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