2016-02-04 65 views
0

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 ins't承認test(this, 'posts')作爲一個函數,它引發以下錯誤:

Uncaught TypeError: listener must be a function

這是爲什麼?

+2

'test(this,'posts')'不是 - 不會返回 - 函數?! – Bergi

+0

'test(this,'posts')'change to'function(){test(thisObj,'posts'); }' –

+2

您正在傳遞函數的結果,而不是函數。 – Seonixx

回答

1

您正在傳遞呼叫結果undefined - 不是函數。我相信你正在尋找

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