题解 | 继承

继承

https://www.nowcoder.com/practice/ee1e5ee81b1c4fbb8c05a4e903621762

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <script type="text/javascript">
      function Human(name) {
          this.name = name
          this.kingdom = 'animal'
          this.color = ['yellow', 'white', 'brown', 'black']
      }

      Human.prototype.getName = function() {
        return this.name;
      }

      function Chinese(name,age) {
          Human.call(this,name)
          this.age = age
          this.color = 'yellow'
      }
      // 将 Chinese 的原型指向 Human 的实例,实现原型链继承
      Chinese.prototype = Object.create(Human.prototype)

      Chinese.prototype.getAge = function() {
        return this.age;
      }

      // 补全代码
    </script>
  </body>
</html>

全部评论

相关推荐

马上要带我人生中的第一个实习生了,想问问大家都喜欢什么的mentor?好让我有个努力的目标
拒绝996的劳伦斯很勇敢:看得见目标且护犊子的 具体就是明确告诉组员要干什么,然后当别的组甩dirty work时能护的组自家新人
点赞 评论 收藏
分享
爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
勤劳的鲸鱼在okr拆解:没有别的选择就去吧,有实习和没实习找工作是天上地下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务