Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is callback function essentially a function inside another function?

why is this wrong:

markImportant({ Id: this.row.Id })
          .then(this.showToast("success"))
          .catch(this.showToast("error"));

And this is right?

markImportant({ Id: this.row.Id })
      .then(() => {
          this.showToast("success");
      })
      .catch(() => {
          this.showToast("error");
      });

I’m passing a function as a paremeter in both cases. The first case is only one function, whereas the second function is a function inside another function as a parameter.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

in .then(this.showToast("success")) you are invoking the showToast function which i believe it returns undefined so you can’t invoke undefined

in then(() => { this.showToast("success")}) you are passing a function which can be invoked so thats why that works

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading