我知道 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/