1、直接继承
本质:重写原型对象
function Game(){
this.name='LOL'
}
Game.prototype.getName=function(){
return this.name
}
function LOL(){
}
LOL.prototype=new Game()
LOL.prototype.constructor=LOL
const game=new LOL()
game.name //'LOL'
game.getName() //'LOL'
1.在原型对象所有属性的方法,都能被实例所共享
追问:业务中为啥不常用直接继承的方式
function Game(){
this.name='LOL'
this.skin=['s']
}
Game.prototype.getName=function(){
return this.name
}
function LOL(){
}
LOL.prototype=new Game()