我正在研究Twitter源代码,我遇到了以下片段:
window.setTimeout=window.setTimeout;window.setInterval=window.setInterval;
编辑:
要查看代码,请转到任何Twitter用户页面,打开页面源,您将在第二个javascript块中看到该片段.@H_301_5@
解决方法
这是一种以跨浏览器方式全局替换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.@H_301_5@
见http://www.adequatelygood.com/2011/4/Replacing-setTimeout-Globally.@H_301_5@