题解 | #类继承#

类继承

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。

全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务