0

I have the following code. After call back is finished, I want to set the boolean to true but it fails with "undefined".

const processor = Processor.createInstance();

class Person {
    private status = {
        failed: true
      }

  processInfo(){

   processor.process(function(d){
       //do stuff now then set stays to false
      this.status.failed = false; //fails with "failed" of undefined.
    });

    }

 }

Attempted solutions:

  1. create a function that sets status.failed to true then pass the function as a parameter to the processInfo() method and call it:

    function setStatus(status) { this.status.failed = status; }

    processInfo(statusUpdater){ processor.process(function(d){ //do stuff now then set stays to false statusUpdater(false); });

    }

still it fails with the same error message.

2nd: pass status object as a parameter to processInfo. It does work but not sure why or if it is the right way.

Hobo
  • 43
  • 6
  • 1
    Have you tried using an arrow function instead of `function`? What do you mean by _“fails with "failed" of undefined”_? Are you getting the error message _“Cannot read property `failed` of `undefined`”_? Do you understand what this error message is trying to tell you? – Sebastian Simon Nov 14 '22 at 01:20

0 Answers0