下面是我的代碼,我得到這個錯誤Unhandled Rejection (TypeError): startPolling.bind(...).then is not a function
.then()不能在setInterval函數中傳遞參數?
setInterval(startPolling.bind(null, id).then(function(response){
if (response.id == 0){
console.log("stop polling")
}
}), 2000)
function startPolling(id){
return callApi('/someUrl/'+id+'','get') // it returns a promise
}
問題:如果我不使用bind
同時呼籲startPolling
然後setInterval
不是每2秒執行代碼 。
如果我使用bind
同時呼籲startPolling
的setInterval正在執行它的方式,但then()
沒有執行,因爲我得到了上述的錯誤
startPolling.bind(...)。然後不是一個函數它是一個承諾 – marvel308
如果它是一個承諾那麼爲什麼我得到這個錯誤'未處理的拒絕(TypeError):startPolling.bind(...)。那麼不是一個函數' – ashwintastic
你通過在setInterval()之外運行它會得到什麼?嘗試運行它並在鏈中添加一個catch並檢查err – marvel308