<body>
<!--
方式2:借用构造函数继承(假的)
1.套路:
定义父类型构造函数
定义子类型构造函数
在子类型的构造函数中调用父类型构造
2.关键
1.在子类型构造函数中通过call()调用父类型构造函数
-->
<script>
function Person(name,age){
this.name = name
this.age = age
}
Person.prototype.setName = function(name){
this.name = name
}
function Student(name,age,price){
Person.call(this,name,age) //相当于:this.Person(name,age)
//!!!!call是为了继承属性
//this.name = name
//this.age = age
this.price = price
}
Student.prototype = new Person()//这个是为了最终能看到父类型的方法
Student.prototype,constructor = Student
Student.prototype.setPrice = function(price){
this.price = price
}
var s = new Student('Tom',20,4000)
s.setName('Bob')
s.setPrice(15000)
console.log(s.name,s.age,s.price) //假的 //简化代码而已
</script>
</body>