Skip to content

Instantly share code, notes, and snippets.

@jmblog
Created August 6, 2012 02:12
Show Gist options
  • Save jmblog/3269147 to your computer and use it in GitHub Desktop.
Save jmblog/3269147 to your computer and use it in GitHub Desktop.
$.Deferred を使って遅延実行
// 参考
// 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