javascript - 如何在 Meteor 中使用参数延迟函数?

标签 javascript asynchronous meteor

我知道 Meteor.defer() 并且想在网络服务响应中使用它,因为可以在发送回响应后完成计算。

但是我的函数需要一个参数,而 Meteor.defer() 只接收一个函数名,没有参数。

我尝试了来自 underscore.js_defer ,但由于这是服务器端代码,我收到一条错误消息,提示 Meteor 代码应始终在纤程内运行。

我有哪些选择?

最佳答案

您可以使用 .bind 为函数预先提供参数:

function test(a, b) {
  console.log(a, b);
}

Meteor.methods({
  test() {
    const testWithParam12 = test.bind(undefined, 1, 2);
    Meteor.defer(testWithParam12);
  }
});

关于javascript - 如何在 Meteor 中使用参数延迟函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156505/

相关文章:

Javascript - 在从函数返回之前等待异步调用完成,而不使用回调

node.js - Gcloud 上的 Meteor react

javascript - Meteor - Sub 的异常(exception)。发布函数返回非游标数组

javascript - 我的服务没有更新 - Angularjs

javascript - Then 不是 axios async/await post 请求的函数

javascript - 是否有更短的方法来提供 Observable onComplete 处理程序?

javascript - 在 jquery $.when(ajax).done(function(){do sth} 中,我如何回调同一个回调函数两次?

jquery - Meteor 和 jQuery : . css 不起作用,.addClass ("css-class") 有效

javascript - 时刻js格式日期

javascript - 如何在不同方向多次绘制一张图像?