<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>

 

posted on 2012-12-15 22:40  somesayss  阅读(5012)  评论(0编辑  收藏  举报