Reputation: 759
A snipit of code that I am using works perfectly when it contains the first line of code shown below. However, when I replace that line with the second line of code shown below, a "TypeError [ERR_INVALID_CALLBACK]: Callback must be a function" error is thrown. Any suggestions on what I might do to fix this problem? Thanks.
getData(body);
setTimeout(getData(body), 0);
Upvotes: 0
Views: 22
Reputation: 45
JavaScript setTimeout(function[, delay, arg1, arg2, ...])
takes the name of the function you want to execute as its first argument. Emphasis on the name of the function. This means getData
in your case instead of getData()
or getData(body)
. The second argument is the time to wait for before the function executes. The next argument (or comma-separated list of arguments) are the argument you want to supply to your function in the order your function expect them. This means written correctly, your code should look like this: setTimeout(getData, 0, body)
.
Seeing that your setTimout
function is not delayed at all by setting delay to 0, you could just call getData(body)
normally and it will do its work. Just saying.
Upvotes: 1