题解 | 继承
继承
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>
查看1道真题和解析