Node callbackNeDB下方正常工作,

Datastore = require 'nedb'
db = new Datastore

db.insert a: 'Hi!', (err, docs) ->
    console.log docs


然后尝试将NeDB Node callback转换为Bacon EventStream

Bacon = require('baconjs').Bacon
Datastore = require 'nedb'
db = new Datastore

insert = Bacon.fromNodeCallback db.insert, a: 'Hi!'

insert.onValue (docs) ->
    console.log docs


为什么它在下面失败了?

TypeError: Cannot call method 'push' of undefined

最佳答案

以这种方式传递db.insert时,您将失去其评估上下文(“ this”不再是数据库)。尝试使用fromNodeCallback的其他形式:

insert = Bacon.fromNodeCallback(db, 'insert', {a: 'Hi!'})

10-05 20:47
查看更多