require
function require(name, callback) {
var newJs = document.createElement('script');
// ie
newJs.onreadystatechange = function(){
if(newJs.readyState === 'loaded' || newJs.readyState === 'complete'){
newJs.onreadystatechange = null;
callback && callback();
}
}
// 正常
newJs.onload = function(){
callback && callback();
}
newJs.src = name;
// document.documentElement 特指 head
document.documentElement.firstChild.appendChild(newJs);
}
借鉴学习来自 O'Reilly JavaScript Patterns