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))
时间: 2024-10-19 22:21:20