题解 | #继承#
继承
https://www.nowcoder.com/practice/ee1e5ee81b1c4fbb8c05a4e903621762
关于继承的关键点:
- 将“Chinese”的原型挂载在“Human”构造函数的实例上
- 修复“Chinese”的原型链(将原型的构造函数指向自己)
<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'
}
// 补全代码
Human.prototype.getName=function(){
return this.name
}
Chinese.prototype=new Human()
Chinese.prototype.constructor=Chinese
Chinese.prototype.getAge=function(){
return this.age
}
</script>
字节跳动公司福利 1290人发布
查看17道真题和解析