我用咖啡腳本編寫node.js,它工作正常,我想知道的是如何在咖啡腳本中返回一個函數的值 ,這裏是我的代碼如何在咖啡腳本中返回一個函數的值
exports.find=->
db.open((err, db)->
unless err
db.createCollection('test', (err, collection)->
unless err
collection.find().toArray((err, items)->
unless err
//here how to return *items*
console.log(items)
)
)
)
巧,如何在另一個模塊中使用這種方法嗎? '分貝=要求( './分貝'); items = db.find(???)' – Mil0R3
@Veelian就像你在示例代碼中使用'db.open'一樣。 'db.find(err,items) - > doSomething(items)' – qiao