题解 | #继承#
继承
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技术