题解 | #类继承#
类继承
https://www.nowcoder.com/practice/c06b31bf07b94c5f9dbef9645e97ea28
思路:使用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关键字调用父级构造函数。
#类继承#前端js面试 文章被收录于专栏
前端js面试,帮助你更好的理解js。
OPPO公司福利 1161人发布
查看10道真题和解析