我有一个名为LangDataService.isDataReady
的变量,这是一个承诺要解决的威胁。在解决一些逻辑会发生。我怎么能把这个转化为那个承诺?如何将'this'传递给Promise,而无需在外部缓存?
LangDataService.isDataReady.then(function() {
this.modalOn()
});
我知道我可以缓存var self_ = this;
但我很好奇其他选择吗?
我有一个名为LangDataService.isDataReady
的变量,这是一个承诺要解决的威胁。在解决一些逻辑会发生。我怎么能把这个转化为那个承诺?如何将'this'传递给Promise,而无需在外部缓存?
LangDataService.isDataReady.then(function() {
this.modalOn()
});
我知道我可以缓存var self_ = this;
但我很好奇其他选择吗?
LangDataService.isDataReady.then(function() {
this.modalOn()
}.bind(this));
我发誓的男人我试图说笑。我必须把它放在错误的地方。 –
史诗!非常感谢matt3141! – Landeeyo
[Arrow功能](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) – Andreas
相信@Andreas指的是以下事实:'箭头函数“有一个词法范围的'this'。 –
@Andreas不幸的是,arrow函数没有得到广泛的支持,babel只会传递给var this_ = this; –