随便来一个load_script实现.
function load_script(xyUrl, callback){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = xyUrl;
script.onload = script.onreadystatechange = function(){
if((!this.readyState || this.readyState === "loaded" || this.readyState === "complete")){
callback && callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
if ( head && script.parentNode ) {
head.removeChild( script );
}
}
};
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
head.insertBefore( script, head.firstChild );
}
当onload或者 onreadystatechange readyState === "loaded" 的时候。
js 加载完毕了。那么此时加载的js执行了吗?不一定执行完。
在seaJs中:
seaJs.use('a.js',function(ooo){
console.log(ooo)// o为a.js exports的对象。那么此时a.js肯定执行过了。
})
请教seaJs.use怎么实现的?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
seajs里是有几种状态来标识文件的加载情况的。 这几种状态是如何界定判断出来的。比如loaded 和 EXECUTED