简体   繁体   English

无法将功能识别为功能?

[英]Function not being recognized as a function?

store.changes takes a function as an argument. store.changes接受一个函数作为参数。 test takes an object and its property as an argument: 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)
}

But for some reason store.changes ins't recognizing test(this, 'posts') as a function, it throws the following error: 但是由于某种原因, store.changes无法将test(this, 'posts')识别为一个函数,它将引发以下错误:

Uncaught TypeError: listener must be a function 未捕获的TypeError:侦听器必须是一个函数

Why is this? 为什么是这样?

You're passing the result of a call, undefined - not a function. 您正在传递undefined的调用结果-不是函数。 I believe you are looking for 我相信你正在寻找

store.changes(() => test(this, 'posts'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM