修改很簡單,透過參數判斷,然後回傳下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)
})