我在研究 Twitter 源代码时,发现了以下片段:
window.setTimeout=window.setTimeout;window.setInterval=window.setInterval;
Twitter 为什么要重新定义这些功能?
编辑: 要查看代码,请转到任何 Twitter 用户页面,打开该页面的源代码,您将在第二个 javascript block 中看到该片段。
最佳答案
这是一种以跨浏览器的方式全局替换 setTimeout
和 setInterval
函数的技术。
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 .
关于javascript - 为什么Twitter要重新定义window.setTimeout和window.setInterval?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8044433/