思路:使用class关键字编写类,使用extends关键字编写类的继承,使用constructor关键字编写构造函数,使用super关键字调用父级构造函数。
<script type="text/javascript">
class Human {
constructor(name) {
this.name = name
this.kingdom = 'animal'
this.color = ['yellow', 'white', 'brown', 'black']
}
getName(){
return this.name
}
}
class Chinese extends Human{
constructor(name,age) {
super(name)
this.age=age
}
getAge(){
return this.age
}
}
</script>
总结:js使用class关键字编写类,js使用extends关键字编写类的继承,js使用constructor关键字编写构造函数,js使用super关键字调用父级构造函数。



京公网安备 11010502036488号