JavaScript 继承实现代码

          function SuperType(name){
            this.name=name;
            this.colors=['black', 'white']
          }
          SuperType.prototype.sayName=function(){
            console.log(this.name);
          }
          function SubType(name, age){
            SuperType.call(this, name);
            this.age=age;
          }
          SubType.prototype=Object.create(SuperType.prototype,{
            constructor:{value: SubType}
          });
      console.log(new SuperType('derek'))
      console.log(new SubType('ben', 25))
 

 

posted @ 2015-04-25 14:46  Derek_Hu  阅读(132)  评论(0编辑  收藏  举报