Node.js 此节点的节点异步库绑定

Node.js 此节点的节点异步库绑定,node.js,asynchronous,coffeescript,Node.js,Asynchronous,Coffeescript,我正在使用异步库() 在尝试与mongoskin()异步执行多个db查询的节点上 问题是在这样使用map函数时 app.post '/events', (req, res) -> storage.events.getByUser req.session.authId, (events) -> async.map events, storage.codes.getCountByEvent, (err, results) -> res.send result

我正在使用异步库() 在尝试与mongoskin()异步执行多个db查询的节点上

问题是在这样使用map函数时

app.post '/events', (req, res) ->
  storage.events.getByUser req.session.authId, (events) ->
    async.map events, storage.codes.getCountByEvent, (err, results) ->
      res.send results
它将
@
绑定到
getCountByEvent
函数上的全局命名空间,有使用异步库的经验的人能给我提供解决此问题的最佳方法的指导吗

下面是
存储.code
实现的示例

class Codes
    constructor: (db) ->
        db.bind 'codes',
            getCountByEvent: (event, callback) ->
                @.find(event: event._id).toArray (err, res) ->
                    callback res.length

        return db.codes

exports.Codes = Codes
async.map
之外调用
getCountByEvent
,可以正常工作


提前感谢

您可以创建绑定到
存储的
getCountByEvent
版本。code
对象:

async.map events, storage.codes.getCountByEvent.bind(storage.codes), ...

那实际上不起作用,我已经试过了。getCountByEvent:(事件,回调)=>是的,这将起作用,我正在寻找一种使用异步框架正确绑定上下文的方法。如果没有人对此有不同的看法,我会接受这个答案。谢谢。@BrianWigfield嗯,这是绑定迭代器上下文的常用方法。Async在后台使用Array::map;如果直接执行相同的操作,则必须以相同的方式绑定迭代器。唯一的替代方法是手动执行相同的操作
bind->(args…)storage.codes.getCountByEvent args…
-但是当您有
bind
时,为什么还要麻烦呢?这绝对是最简单的方法<代码>异步不支持传入上下文参数。如果这是在客户端,@Flambino的建议也有效。