store.changes
采用函数作为参数。 test
将对象及其属性作为参数:
store.changes(test(this, 'posts'))
function test (obj, prop) {
store.find().then(posts => {
obj[prop] = _.map(posts.rows, (post) => post.doc)
})
}
store.changes = (func) => {
return db.changes({
since: 'now',
live: true
}).on('change', func)
}
但由于某种原因 store.changes
无法将 test(this, 'posts')
识别为函数,它会抛出以下错误:
Uncaught TypeError: listener must be a function
这是为什么?
最佳答案
您正在传递调用的结果,未定义
- 不是函数。我相信您正在寻找
store.changes(() => test(this, 'posts'));
关于javascript - 函数不被识别为函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35206484/