题解 | #继承#

继承

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技术

全部评论

相关推荐

怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
2
2
分享

创作者周榜

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