07 2012 档案
摘要:// 声明MyNamespace.Singleton = (function(){ // 私有属性 var uniqueInstance;// 创建记录 // 私有方法 function constructor(){ var attribute = 100; // 闭包属性 function method(){ // 闭包方法 // ... } } // 公共方法 return { getInstance:function(){// 创建实例 // 如果记录不存在 if(!uniqueInstance){ uniqueInstance = constructor();...
阅读全文
摘要:1 /*********对象冒充**********/ 2 function Parent(username){ 3 this.username=username; 4 this.sayHello=function(){ 5 alert(this.username); 6 } 7 } 8 function Child(username,password){ 9 this.method=Parent;10 this.method(username);11 ...
阅读全文
摘要:1 var GiantCorp=window.GiantCorp || {} 2 GiantCorp.DataParser={ 3 _stripWhitespace:function(str){ 4 return str.replace(/\s+/,''); 5 }, 6 _stringSplit:function(str,delimiter){ 7 return str.split(delimiter); 8 }, 9 stringToArray:...
阅读全文
摘要:1 function extend(subClass,superClass){ 2 var f=function(){}; 3 f.prototype=superClass.prototype; 4 subClass.prototype=new f(); 5 subClass.prototype.constructor=subClass; 6 7 subClass.superClass=superClass.prototype; 8 if(superClass.prototype.constructor==Object.prototype.c...
阅读全文
摘要:1 var Book=(function(){ 2 var numOfBooks=0; 3 function checkIsbn(isbn){ 4 5 } 6 return function(isbn,title,author){ 7 var _isbn,_title,_author; 8 9 this.setIsbn=function(isbn){10 _isbn=isbn;11 }12 ...
阅读全文
摘要:1 /** 2 * 创建接口对象 3 * @param name 接口名 4 * @param methods 接口方法 5 */ 6 var Interface = function(name,methods){ 7 if(arguments.length != 2){ 8 throw new Error('必须输入两个参数,当前个数'+arguments.length); 9 }10 11 this.name=name;12 this.meth...
阅读全文
摘要:1 Function.prototype.method=function(name,fn){2 this.prototype[name]=fn;3 }
阅读全文

浙公网安备 33010602011771号