我正在研究Twitter源代码,我遇到了以下片段:
window.setTimeout=window.setTimeout;window.setInterval=window.setInterval;
为什么Twitter重新定义了这些功能?
解决方法
这是一种以跨浏览器方式全局替换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.