zoukankan      html  css  js  c++  java
  • JavaScript之子类构建工具

    (function(){
    	var initializing = false;
    	var superPattern = /xyz/.test(function(){ xyz; }) ? /_super/ : /.*/;
    	
    	Object.subClass = function(properties){//给Object添加一个subClass方法
    		var _super = this.prototype;//初始化超类
    		initailizing = true;
    		var proto = new this();
    		
    		for(var name in properties){
    			proto[name] = typeof properties[name] == "function" && typeof _super[name] == "function" && superPattern.test(properties[name]) ?
    			(function(name,fn){//定义一个重载函数
    				return function(){
    					var tmp = this._super;
    
    					this._super = _super[name];
    
    					var ret = fn.apply(this,arguments);
    					this._super = tmp;
    					return ret;
    				}
    			})(name,properties[name]) : properties[name];  
    		}
    	}
    
    	function Class(){
    		if(!initializing && this.init){//创建一个仿真类构造器
    			this.init.apply(this.arguments);
    		}
    		
    		Class.prototype = proto;//设置类的原型
    
    		Class.constructor = Class;//重载构造器引用
    
    		Class.subClass = arguments.callee;//让类继续可扩展
    
    		return Class;		
    	}	
    })()
    
  • 相关阅读:
    jdbc代码
    openwrt vsftp
    openwrt 配置samba && ubuntu 配置samba
    如何学习开源项目
    Makefile 笔记
    Samba 学习笔记
    quilt-补丁工具
    to-do-list
    新增feeds模块
    linux命令
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/7893826.html
Copyright © 2011-2022 走看看