本文介绍了setTimeout-回调参数必须是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码一直有效,直到我将node.js更新到版本8.11.3
My code was working until i updated node.js to version 8.11.3
现在,在尝试调用时,我总是收到错误消息回调参数必须是一个函数
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-回调参数必须是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!