<script> // 1. 父类 function Father() { this.type = 'father'; this.names = ['tom', 'kevin']; } // 2.给父类Father的原型对象添加getName方法 Father.prototype.getName = function() { console.log(this.names); } // 3.创建父类的实例 var father = new Father(); // console.log(father); // 2. 子类 function Child() { } // 3. 让子类的原型对象等于父类的一个实例, 完成原型链继承 Child.prototype = father; // 4. 创建一个子类实例 var child = new Child(); console.log(child); // 5. 创建另外一个实例 var child2 = new Child(); console.log(child2); // 6. 缺点展示: 给其中一个实例的names添加一个成员 child2.names.push('zs'); console.log('child2.names', child2.names); console.log('child.names', child.names); // 不是引用类型,不受影响 child2.type = 'aaaa'; console.log('child2.type', child2.type); console.log('child.type', child.type);</script>