gpt4 book ai didi

javascript - 箭头函数不是函数

转载 作者:行者123 更新时间:2023-12-02 14:10:41 25 4
gpt4 key购买 nike

我收到以下错误TypeError: f is not a function:我做错了什么?

var expressws = require("express");
var appws = expressws();
var expressWs = require('express-ws')(appws);

function x(ws)
{
console.log("send");
}

function loop(f,t)
{
setTimeout(() => loop(), t);
f();
}

appws.ws('/', function(ws, req) {
ws.on('message', function(msg){
var data = JSON.parse(msg);
if(data.action == "Logged in"){
loop(() => x(ws),1000);
}
});

});

最佳答案

以下间接递归调用不会将任何内容作为参数传递给 loop,因此会出现错误。

setTimeout(() => loop(/* should pass two arguments here */), t);

关于javascript - 箭头函数不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39611852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com