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))
相關文章
相關標籤/搜索