setTimeout - 回调参数必须是一个函数 [英] setTimeout - callback argument must be a function
本文介绍了setTimeout - 回调参数必须是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码一直在工作,直到我将 node.js 更新到 8.11.3 版
My code was working until i updated node.js to version 8.11.3
现在我在尝试使用 setTimeout 调用函数时总是收到错误回调参数必须是函数".
Now i always get error "callback argument must be a function" when trying to call a function with setTimeout.
function testFunction(itemid, price) {
var url = 'https://example.com';
var options = {
method: 'get',
url: url
}
request(options, function (err, res, body) {
var response = JSON.parse(body);
if(response.status == 'fail'){
setTimeout(testFunction(itemid, price), 100);
}
})
}
推荐答案
setTimeout
的回调参数必须是一个函数.像这样写.未经测试,但应该可以使用.
Callback argument for setTimeout
must be a function. Write it like this. Not tested but it should work.
function testFunction(itemid, price) {
var url = 'https://example.com';
var options = {
method: 'get',
url: url
}
request(options, function (err, res, body) {
var response = JSON.parse(body);
if(response.status == 'fail'){
setTimeout(function () {
testFunction(itemid, price);
}, 100);
}
})
}
这篇关于setTimeout - 回调参数必须是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文