Why is Twitter overriding window.setTimeout and window.setInterval?

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

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

Why is Twitter overriding these features?

Edit: To see the code, go to any Twitter user page, open the page source, and you will see this fragment in the second javascript block.

+6
source share
1 answer

This is a method of replacing the setTimeout and setInterval functions globally in cross-browser mode.

window.setTimeout , when used as an lvalue (on the left side of the destination), does not go through the prototype chain, but on the right, it does. This way it will always infer the property from the prototype and lay it directly on the object.

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

+15
source

Source: https://habr.com/ru/post/900982/


All Articles