为什么Twitter重新定义window.setTimeout和window.setInterval? [英] Why does Twitter redefine window.setTimeout and window.setInterval?

查看:106
本文介绍了为什么Twitter重新定义window.setTimeout和window.setInterval?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Twitter源代码,我遇到了以下片段:

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

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

为什么Twitter会重新定义这些功能?

Why does Twitter redefine these functions?

编辑:
要查看代码,请转到任何Twitter用户页面,打开页面源,您将在第二个javascript块中看到该片段。

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.

推荐答案

这是一种替换 setTimeout setInterval 函数的技术全球采用跨浏览器方式。

This is a technique to replace setTimeout and setInterval functions globally in a cross-browser fashion.


window.setTimeout ,当用作一个左值(在
赋值的左侧),不会走原型链,但在右侧,它是
。因此,这将始终从原型
链中拉出一个属性并将其放在对象上。

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.

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

这篇关于为什么Twitter重新定义window.setTimeout和window.setInterval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆