最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does Twitter redefine window.setTimeout and window.setInterval? - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Nov 8, 2011 at 0:19 jonathancardoso asked Nov 8, 2011 at 0:07 jonathancardosojonathancardoso 12.8k8 gold badges54 silver badges73 bronze badges 1
  • What's the context? I don't think this question is answerable without a link to the full code. – nrabinowitz Commented Nov 8, 2011 at 0:12
Add a ment  | 

1 Answer 1

Reset to default 15

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./2011/4/Replacing-setTimeout-Globally.

发布评论

评论列表(0)

  1. 暂无评论