题解 | #继承#

继承

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

//考查js继承的几种方式
//如下使用寄生式组合继承
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 (){
                returnthis.name
            }
            //Chinese.prototype = new Human()
            Chinese.prototype = Object.create(Human.prototype)
            Chinese.prototype.getAge = function(){
                returnthis.age
            }

全部评论

相关推荐

Pandaileee:校友加油我现在也只有一个保底太难了
点赞 评论 收藏
分享
joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
3 收藏 评论
分享
牛客网
牛客企业服务