节点asynchronous库绑定这个

我正在使用asynchronous库( https://github.com/caolan/async )在节点上尝试执行与mongoskin( https://github.com/guileen/node-mongoskin )asynchronous的多个db查询

问题是使用像这样的地图function

app.post '/events', (req, res) -> storage.events.getByUser req.session.authId, (events) -> async.map events, storage.codes.getCountByEvent, (err, results) -> res.send results 

它将@绑定到getCountByEvent函数上的全局名称空间,是否有任何具有asynchronous库经验的人能够给我指导最好的方法来解决这个问题?

这是storage.codes实现的示例

 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 

调用getCountByEvent之外的async.map它会正常工作

提前致谢

您可以创build绑定到storage.codes对象的getCountByEvent版本:

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