Created
August 6, 2012 02:12
-
-
Save jmblog/3269147 to your computer and use it in GitHub Desktop.
$.Deferred を使って遅延実行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 参考 | |
// http://tokkono.cute.coocan.jp/blog/slow/index.php/programming/how-happy-with-jquery-deferred-for-your-applications/ | |
(function($) { | |
$.timeout = function(time) { | |
return $.Deferred(function(dfd) { | |
setTimeout(dfd.resolve, time); | |
}).promise(); | |
}; | |
for (var i = 0; i < 5; i++) { | |
var cnt = 0; | |
$.timeout(1000 * i).then(function() { | |
console.log(cnt); | |
cnt++; | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment