To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

javascript Klass 实现

var Klass=function(Parent,props){
            var Child,F,i;
            Child=function(){
                if(Child.uber && Child.uber.hasOwnProperty("__construct")){
                    Child.uber.__construct.apply(this,arguments);
                }
                if(Child.prototype.hasOwnProperty("__construct")){
                    Child.prototype.__construct.apply(this,arguments);
                }
            }
            Parent=Parent || Object;
            F=function(){};
            F.prototype=Parent.prototype;
            Child.prototype=new F();
            Child.uber=Parent.prototype;
            Child.prototype.construct=Child;

            for(var i in props){
                if(props.hasOwnProperty(i)){
                    Child.prototype[i]=props[i];
                }
            }
            return Child;
        }

 

posted on 2013-07-07 11:45  Ijavascript  阅读(227)  评论(0编辑  收藏  举报