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
1 Answer
Reset to default 15This 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.