题解 | #寄生组合式继承#

寄生组合式继承

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

只要懂寄生组合式继承的核心,做这道题就跟写hello world一样

function Human(name) {
  this.name = name
  this.kingdom = 'animal'
  this.color = ['yellow', 'white', 'brown', 'black']
}

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

Chinese.prototype.__proto__ = Human.prototype

Human.prototype.getName = function () {
	return this.name
}

Chinese.prototype.getAge = function () {
	return this.age
}

全部评论

相关推荐

02-24 17:39
门头沟学院 Java
神哥不得了:神哥来啦~专业技能的话建议不要前面空那么多,八股的话建议先把高频top 50的八股多巩固几遍,千万不要看那些假高频八股。项目的话,建议换两个高质量的项目上去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务