前端学习笔记202309学习笔记第九十二天-this指向问题9

class Father{
    constructor(){
        this.age=18
    }
    swim(){
        console.log("Go Swimming")
    }
}

class Son extends Father{
    constructor(){
         super()
        this.hobby="playing"
    }
    study(){
        console.log(this)
        this.swim()
    }
}
const son=new Son()
son.study()

运行结果

 

posted @ 2023-09-18 21:21  前端导师歌谣  阅读(8)  评论(0)    收藏  举报  来源