1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

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

Discussão em 'Angular' iniciado por Levente, Outubro 5, 2024.

  1. Levente

    Levente Guest

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

    Here is my problem:

    export class XY
    {
    property: boolean;
    //other properties

    constructor()
    {
    this.property = false;
    }

    setproperty(e) // this is an onclick event handler
    {
    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 is "undefined" and "unreachable".

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

    Continue reading...

Compartilhe esta Página