0

I have a function (method) that returns a function, and it's being used in a class:

  public myMethod(): (row: number) => number {
    return (row) => {
      const newData = this.form[row]; // this.form is not defined

When returning the function (with row argument), I don't have access to this anymore. How should I refactor the function so that it has access to this of the class?

sir-haver
  • 3,096
  • 7
  • 41
  • 85
  • 1
    You're probably using something like `takeCallback(obj.myMethod)` change it to `takeCallback(() => obj.myMethod())` or change the definition to `public myMethod = (): ((row: number) => number) => {` – VLAZ Sep 28 '22 at 07:47
  • Oh right, so by changing the definition to the syntax you wrote I changed it into an arrow function? Thank you so much – sir-haver Sep 28 '22 at 07:51

0 Answers0