Skip to content

Instantly share code, notes, and snippets.

@kanreisa
Created June 13, 2011 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanreisa/1022243 to your computer and use it in GitHub Desktop.
Save kanreisa/1022243 to your computer and use it in GitHub Desktop.
Countdown - Call Function When Finished Countdown
/**
* Countdown - Call Function When Finished Countdown
**/
var Countdown = Class.create({
initialize: function(pInitialValue, pFunction){
this.i = pInitialValue;
this.f = pFunction;
},
turn: function(){
--this.i;
if(this.i == 0){
this.f();
}
}
});
/* 使い方の例:
var urls = [
'http://example.cdn/A.lib.js',
'http://example.cdn/B.lib.js',
'http://example.cdn/C.lib.js'
];
var hoge = new Countdown(urls.length, function(){
alert('done!');
});
urls.each(function(url){
//ここにロードするコードをかく
hoge.turn();//Ajax.Request完了時に呼ぶとかonloadで呼ぶとか
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment