<script type="text/javascript">//组合继承: 将原型链和借用构造函数的技术组合在一起//使用原型链实现对原型方法的继承//使用构造函数实现对实例属性的继承//js中最常用的继承方式//super:超类function SuperType(name) {//超类属性//使用构造函数实现对实例属性的继承this.name = name;this.colors = ['red','blue','green'];}SuperType.prototype.sayName = function() {//超类方法//使用原型创建函数,以实现函数的复用console.log(this.name)}//sub:子类function SubType(name,age) {//继承属性//使用call()方法 每次创建之类实例的时候,超类的属性会存一份副本到子类实例中//所有子类实例在修改继承的超类属性时,无法影响其他实例SuperType.call(this,name);this.age = age;}//继承方法SubType.prototype = new SuperType();//使用原型对超类方法的继承SubType.prototype.constructor = SubType;//创建子类的方法SubType.prototype.sayAge = function() {console.log(this.age)}//instance:实例const instance1 = new SubType('Nicholas', 29);instance1.colors.push('black');console.log(instance1.colors);instance1.sayName();instance1.sayAge();const instance2 = new SubType('Greg', 27);console.log(instance2.colors);instance2.sayName();instance2.sayAge();//使用instanceof和isPrototypeOf()识别基于组合继承创建的对象console.log(instance1 instanceof SubType);//trueconsole.log(instance1 instanceof SuperType);//true</script>