0

consider the below:

class foo(){
   constructor(){this.x = 10}
   f(){console.log(this.x)}
}
myfoo = new foo()
class bar{
    constructor()
    b(func){func()}
}
mybar = new bar()
mybar.b(myfoo.f)

Because of how this works in javascript, "this" in myfoo.f points to mybar instead of myfoo. How do i go around this? Also if anyone know, why does javascript do this?

smaillis
  • 298
  • 3
  • 12

0 Answers0