javascript - 如何在不在外部缓存的情况下将 'this' 传递给 Promise?

标签 javascript caching asynchronous promise this

<分区>

我有一个名为 LangDataService.isDataReady 的变量,它是一个等待解决的 Promise。解决后会发生一些逻辑。我怎样才能将它传递给那个 Promise?

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

我知道我可以缓存 var self_ = this; 但我对其他替代方案感到好奇?

最佳答案

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

关于javascript - 如何在不在外部缓存的情况下将 'this' 传递给 Promise?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34819252/

相关文章:

javascript - 使用 Google Drive Rest API 更新文件名

javascript - CKEditor 的 HTML 文件上传插件

javascript - 我们可以使用另一个函数名称作为方法的参数从 javascript 调用 native 方法吗?

caching - 告诉浏览器不要缓存的正确方法是什么?

php - 使用 apc_cache 和存储到文件之间的区别?

flutter - While 循环停止计时器运行 (Dart)

node.js - 异步并行请求 - 部分渲染

javascript - 可以使用 Postman 访问本地端点,但不能使用 Axios

javascript - 将元素放置在容器中

python Cachetools 项目可以有不同的 ttl 吗?