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.price = price
}
Student.prototype = new Person() // 得到方法
Student.prototype.constructor = Student // 修正constructor属性
Student.prototype.setPrice = function(price){
this.price = price
}
JS组合继承
最新推荐文章于 2024-05-28 15:52:27 发布