JS_Class.extend


<script type="text/javascript">
var Class = {
    create:function(){
        return function(){
            this.init.apply(this,arguments);
            }
        },
    extend:function(current,target,futher){
        for(var i in target.prototype){
            current.prototype[i] = target.prototype[i]
            }
         for(var j in futher){
            current.prototype[j] = futher[j]
            }
        var _init1 = target.prototype["init"],
            _init2 = futher["init"],
            _Parameter1 = _init1.toString().split("(")[1].split(")")[0],
            _Parameter2 = _init2.toString().split("(")[1].split(")")[0],
            _body1 = _init1.toString().split("{")[1].split("}")[0],
            _body2 = _init2.toString().split("{")[1].split("}")[0];
        eval('current.prototype.init=function('+_Parameter1+','+_Parameter2+'){'+_body1+_body2+'}');
        }
    }
var demo1 = Class.create();
demo1.prototype = {
    init:function(xinming){
        this.name = xinming
        },
    show:function(){
        alert(this.name)
        }
    }
var demo2 = Class.create();
Class.extend(demo2,demo1,{
    init:function(xinbie){
        this.xinbie = xinbie;
        },
    sex:function(){
        alert(this.xinbie)
        }
    });
new demo2("shao","nan").sex();
</script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM