修改很简单,通过参数判断,然后返回下promise对象

(function() {
var timeout = setTimeout;
window.setTimeout = function(fn, time) {
if (!time) {
time = fn;
return $.Deferred(function(dfd) {
timeout(function() {
dfd.resolvel(dfd);
}, time);
}).promise();
}
timeout.apply(window, arguments);
}
})();

 

调用

setTimeout(1000).done(function(dnt) {
console.log(dnt)
})
05-11 14:50