gpt4 book ai didi

javascript - 使用 async.apply 时如何保持 this 的值?

转载 作者:行者123 更新时间:2023-11-29 20:34:41 27 4
gpt4 key购买 nike

<分区>

我正在使用 async.parallel 一次运行 2 个函数,它们是从 mongoose 模型上的静态函数运行的。如您所见,我可以通过 this 访问模型及其在此代码中的函数(该模型有一个名为 verifyParent 的静态函数):

async.parallel([
async.apply(content, {slug: slug}),
async.apply(this.verifyParent, req.body.reply),
], (err, result) => {
//results
});

但是在 this.verifyParent 函数中,如果我尝试使用 this,它等于我的 express 应用程序,而不是 mongoose 模型。我相信 async.apply 正在这样做,但我不知道如何让它保持通常具有的 this 值。

在 verifyParent 中,我正在尝试查询 mongodb。当我运行 this.findOne() 时,它说它不是一个函数,而且看起来这似乎表明它设置了应用程序,而不是模型。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com