-
-
Save kaixiang-li/2299786 to your computer and use it in GitHub Desktop.
script loader,load all the scripts from the script array
This file contains 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
var a = "I'm a"; |
This file contains 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
var b = "I'm b"; |
This file contains 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
var c = "I'm c"; |
This file contains 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(window){ | |
var group = [],queue = {}, | |
head = document.head || document.getElementsByTagName("head")[0]; | |
function require(scripts,callback,context){ | |
group = group.concat(scripts); | |
context = context || this; | |
for( var i = 0 ; i < group.length ; i++){ | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
if(queue[group[i]]){ | |
//alert( group[i] + " has loaded"); | |
continue; | |
} | |
if(script.readyState){ //for IE | |
script.onreadystatechange = function(){ | |
var readyState = this.readyState; | |
if(readyState == "loaded" || readyState == "complete"){ | |
this.onreadystatechange = null; | |
callback.call(context); | |
} | |
}; | |
} | |
else{ | |
script.onload = function(){ | |
callback.call(context); | |
} | |
} | |
queue[group[i]] = true; | |
script.src = group[i] + ".js"; | |
head.appendChild(script); | |
} | |
} | |
window.require = require; | |
})(this); |
This file contains 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
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<script type="text/javascript" src="loader.js"></script> | |
<script type="text/javascript"> | |
require(["a","b","c"],function(){ | |
alert(a + b + c); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
嗯写错了 改掉:)