Confused about this & getcontext js/ts and how to get around it

31 views Asked by At

So, i have a problem where i'm constantly running into undifined errors, (in browser) and seemingly can't figure out why / how to get around it. From what i've gathered is that the keyword "this" is an utterly confusing mess in js & inherently in ts too.

Here is my problme:

export class XY
{
   property: boolean;
    //other proprs
   constructor()
    {this.property = false;}

 setproperty(e) //this is an onclick event
 {
  this.property = true;
 //my problem is that this.property doesn't refer to class member variable "property"
 }
}

even if i try something like const boundGet = XY.bind.(xy), it still undefined and "unreachable"

if not with the keyword "this", how am i supposed to refer to member variable property without making it const??

1

There are 1 answers

0
Levente On

So, turns out the problem was with Devextreme's event binding. If you want to override their datagrids controls "edit" buttons event, you have to pass the event like this [onClick]="yourfunc" now that's obviously not the standard (event)="blabla". Whatever happens in the background messes up the context for "this". went around the problem by using a different event.