题解 | 继承

继承

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>

全部评论

相关推荐

字节一直是我的白月光,考虑到转正还是拒了日常实习。
从今天开始狠狠卷JV...:为什么你释放的offer没流到我头上
点赞 评论 收藏
分享
买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-25 19:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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