-1

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??

Levente
  • 25
  • 5
  • [How does the “this” keyword work?](https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – Andreas Aug 10 '21 at 09:49
  • 1
    Does this answer your question? [How to access the correct \`this\` inside a callback](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – Andreas Aug 10 '21 at 09:51
  • i'll read both and update, thanks! – Levente Aug 10 '21 at 09:52
  • The issue here is that you're not correctly initializing the instance member in the constructor. Should be: `constructor() { this.property = false; }` – lbsn Aug 10 '21 at 10:30
  • made an edit. I do i my code, just copied it improperly, to stack overflow lol. – Levente Aug 10 '21 at 11:18

1 Answers1

0

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.

Levente
  • 25
  • 5