0

I have two recursive functions and when I call one of them inside the other I get the following error cannot read property 'date' of undefined. Here is my code. I am using TypeScript.

export class FormFiller {
    
    fill(index = 0): any {
      const fillTypeFunction = this.date();
      if (fillTypeFunction) {
        fillTypeFunction('arg1', 'arg2');
      } else {
        throw new Error("Couldn't find a function");
      }
      return this.fill(index + 1);
    }
    
    date(qid: string, val?: string): any {
      const elem = $(el);
      if (elem.attr('ng-reflect-value')) {
        console.log('Data is set');
      } else {
        this.date(qid, val);
      }
    }
}

How can I manage to make date() recursive function to work inside fill() function?

Ara Galstyan
  • 486
  • 1
  • 4
  • 11

0 Answers0