当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  Sys.ScriptLoader与JS加载进度条的实现(2)

 Sys.ScriptLoader与JS加载进度条的实现(2)

点击次数:27 次 发布日期:2008-11-26 12:31:04 作者:源代码网
源代码网推荐      事实上,Sys.ScriptLoader的代码非常简单,我添加的注释越看越像画蛇添足。值得注意的是所有的资源都被尽可能的释放。尤其注意从第99行开始的代码,if体内首先用临时变量保留两个全局变量,然后再将全局变量释放。其目的就是避免在completionCallback在执行时抛出异常而导致的内存泄露,即使只有万分之一的可能性。Javascript越多,则越容易造成内存泄露,在编写JS代码时最好注意这方面的问题。
源代码网推荐  
源代码网推荐    接着解释一下load方法的第一个参数references,原本以为这一个Sys.Reference类的数组,结果发现其实相差甚远。不管怎么样顺便看一下该类的代码。
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   1Sys.Reference = function() {
源代码网推荐   2
源代码网推荐   3 var _component;
源代码网推荐   4 var _onload;
源代码网推荐   5
源代码网推荐   6 this.get_component = function() {
源代码网推荐   7 return _component;
源代码网推荐   8 }
源代码网推荐   9 this.set_component = function(value) {
源代码网推荐  10 _component = value;
源代码网推荐  11 }
源代码网推荐  12
源代码网推荐  13 this.get_onscriptload = function() {
源代码网推荐  14 return _onload;
源代码网推荐  15 }
源代码网推荐  16 this.set_onscriptload = function(value) {
源代码网推荐  17 _onload = value;
源代码网推荐  18 }
源代码网推荐  19
源代码网推荐  20 this.dispose = function() {
源代码网推荐  21 _component = null;
源代码网推荐  22 }
源代码网推荐  23
源代码网推荐  24 this.getDescriptor = function() {
源代码网推荐  25 var td = new Sys.TypeDescriptor();
源代码网推荐  26
源代码网推荐  27 td.addProperty("component", Object);
源代码网推荐  28 td.addProperty("onscriptload", String);
源代码网推荐  29 return td;
源代码网推荐  30 }
源代码网推荐  31}
源代码网推荐  32Sys.Reference.registerSealedClass("Sys.Reference", null, Sys.ITypeDescriptorProvider, Sys.IDisposable);
源代码网推荐  33Sys.TypeDescriptor.addType("script", "reference", Sys.Reference);
源代码网推荐    关心一下Sys.ScriptLoader类的代码可知,reference数组的每个元素其实只是简单的“{ url : "http://www.sample.com/sample.js", onscriptload : "alert(1)"}”形式的对象。不过这样也好,想构造这么一个数组也能轻易地使用JSON了。
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华