bind

it2023-05-07  77

class father{ get fruit(){ return 'apple' } eat(){ console.log('我要吃苹果'+this.fruit) } constructor(){ this.eat=this.eat.bind(this) } } class Son{ get fruit(){ return 'apple1' } eat(){ console.log('我要吃苹果1'+this.fruit) } } var son1=new Son(); var father1=new father(); son1.eat=father1.eat son1.eat()//吃父亲的苹果 、、我要吃苹果apple
最新回复(0)