<script> // 1.创建父类 function Father(name, age) { this.name = name; this.age = age; this.list = [1, 2, 3]; } // 2.给父类的原型对象添加say方法 Father.prototype.say = function() { console.log('hello'); } // 3.创建子类 function Child(name, age) { // 4.借用父类构造函数 Father.call(this, name, age); } // 5.让子类的原型对象等于父类的一个实例,这样子类就继承了父类的所有属性和方法,new Father时可以传参也可以不传 Child.prototype = new Father('张无忌', 50); // 6.创建子类实例 var child = new Child('张三', 18); console.log('child', child); var child2 = new Child('李四', 20); console.log('child', child2); console.log(child.list === child2.list); //false,引用类型属性不会相互影响</script>