【发布时间】:2012-08-17 21:58:57
【问题描述】:
阅读 jQuery 1.8 源码,
为什么 setTimeout 延迟为 0 毫秒? (而不仅仅是执行回调?)
https://github.com/jquery/jquery/blob/1.8.0/src/ajax/xhr.js#L196
if ( !s.async ) {
callback();
} else if ( xhr.readyState === 4 ) {
// (IE6 & IE7) if it's in cache and has been
// retrieved directly we need to fire the callback
//-------->// WHY do setTimeout with 0 ms delay ?
setTimeout( callback, 0 );
} else {
handle = ++xhrId;
【问题讨论】:
-
@Strelok 并不是真正的重复恕我直言,尽管它是相关的。在这种情况下,需要维护与程序员的功能合同,而不是解决任何特定问题。
-
啊,其实是为了解决IE6/7的一个特性