Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass 'this' into a Promise without caching outside? [duplicate]

I have a variable called LangDataService.isDataReady that is a Promise wawiting to be resolved. Upon resolve some logic will happen. How can I pass this into that Promise?

LangDataService.isDataReady.then(function () {
    this.modalOn()
});

I know i can cache var self_ = this; but I'm curious of other alternatives?

like image 416
Armeen Harwood Avatar asked Jan 15 '16 20:01

Armeen Harwood


1 Answers

LangDataService.isDataReady.then(function () {
  this.modalOn()
}.bind(this));
like image 101
matt3141 Avatar answered Oct 12 '22 13:10

matt3141