Created
August 20, 2012 07:38
-
-
Save xiaojue/3401897 to your computer and use it in GitHub Desktop.
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
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