Skip to content

Instantly share code, notes, and snippets.

@xiaojue
Created August 20, 2012 07:38
Show Gist options
  • Save xiaojue/3401897 to your computer and use it in GitHub Desktop.
Save xiaojue/3401897 to your computer and use it in GitHub Desktop.
function loadByqueue(list,type,callback){
var queue = [],
_load = {
"sync":function(list){
var src = list[0];
if(!src) callback();
$.getScript(src,function(){
list.shift();
_load["sync"](list);
});
},
"asyn":function(list){
var list = list.reverse(),len = list.length;
queue.length = len;
while(len--){
var src = list[len];
(function(i){
$.getScript(src,function(){
queue[i] = true;
for(var k=0;k<queue.length;k++){
if(!queue[k]) break;
if(queue[k] && k === queue.length) callback();
}
});
})(len);
}
}
}
_load[type](list);
}
loadByqueue(["1.js","2.js","3.js"],"asyn",function(){
console.log("all loaded");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment