题解 | #继承#

继承

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

<script type="text/javascript">
function Human(name) {
    this.name = name
    this.kingdom = 'animal'
    this.color = ['yellow', 'white', 'brown', 'black']
}

function Chinese(name,age) {
    Human.call(this,name)
    this.age = age
    this.color = 'yellow'
}

// 补全代码
// 1.给"Human"构造函数的原型对象添加"getName"方法,返回当前实例"name"属性
Human.prototype.getName = function(){
    return this.name
}
// 2.将"Chinese"构造函数继承于"Human"构造函数
Chinese.prototype = Human.prototype
// 3.给"Chinese"构造函数的原型对象添加"getAge"方法,返回当前实例"age"属性
Chinese.prototype.getAge = function(){
    return this.age
}

</script>

#JavaScript#
在线编程题解 文章被收录于专栏

web技术

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享
07-03 16:02
门头沟学院 Java
今天面试,非常紧张,面试官问我springboot有哪些核心模块都答不上来了,真的对自己无语了!
程序员小白条:28届我勒个去,很多人面试都没机会
查看1道真题和解析
点赞 评论 收藏
分享
评论
2
2
分享

创作者周榜

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