这些什么意思
(function(global){function loadModule(){
var LoadUtil = {};
LoadUtil.loadJs = function(src) {
document.write('<' + 'script language="javascript" type="text/javascript"');
document.write(' src="' + src + '">');
document.write('<'+'/script'+'>');
};
LoadUtil.loadAsyncJs = function(src, callback,rootObject){
var se = document.createElement('script');
se['type'] = "text/javascript";
se['src'] = src;
se['async'] = true;
if(typeof callback == 'function'){
// IE 下的 script 标签有 onreadystatechange 事件,无 onload 事件
if (se['onreadystatechange']) {
se['onreadystatechange'] = function () {
if (this.readyState == "complete" || this.readyState == "loaded") {
callback();
}
};
}else{
// W3C 标准的 script 标签没有 onreadystatechange 和 this.readyState
se['onload'] = function(){
callback();
}
}
}
rootObject = rootObject || document.getElementsByTagName('head')[0];
rootObject.appendChild(se);
};
//异步加载多个js, js串行处理
LoadUtil.asyncSerialLoadResources = function (resources, callback,rootObject) {
var totalCount = resources.length, curIndex = -1, self = this;
var loadSingleFun;
loadSingleFun = function () {
curIndex++;
if (curIndex >= totalCount) {
callback();
} else {
var url = resources[curIndex];
if (url) {
self.loadAsyncJs(url, loadSingleFun,rootObject);
} else {
loadSingleFun();
}
}
};
loadSingleFun();
};
//异步加载多个js, js串并行处理
LoadUtil.asyncParallelLoadResources = function (resources, callback,rootObject) {
var totalCount = resources.length;
var finishCount = 0;
for (var i=0; i<totalCount; i++) {
self.loadAsyncJs(resources[i], function(){
if (++finishCount >= totalCount) {
callback();
}
},rootObject);
}
};
return LoadUtil;
};
if (typeof module != 'undefined' && module["exports"]) { // CommonJS
module["exports"] = loadModule();
} else if (typeof define != 'undefined' && define["amd"]) { // AMD
define(loadModule);
} else { // Shim
global["LoadUtil"] = loadModule();
}
})(this);