javascript – 为什么Twitter重新定义window.setTimeout和window.setInterval?

前端之家收集整理的这篇文章主要介绍了javascript – 为什么Twitter重新定义window.setTimeout和window.setInterval?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究Twitter源代码,我遇到了以下片段:
window.setTimeout=window.setTimeout;window.setInterval=window.setInterval;

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

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

解决方法

这是一种以跨浏览器方式全局替换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.

原文链接:https://www.f2er.com/js/156115.html

猜你在找的JavaScript相关文章