Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Socket.io 类实例不会在其内部保存套接字_Socket.io - Fatal编程技术网

Socket.io 类实例不会在其内部保存套接字

Socket.io 类实例不会在其内部保存套接字,socket.io,Socket.io,每当新用户连接到socket.io时,事件处理程序就会为该用户创建一个名为Events的新类 const eventHandler=socket=>{ 新事件(socket); }; 事件构造函数将其套接字设置为创建时给定的套接字 类事件{ 构造函数(套接字){ this.socket=socket; this.socket.on('test',this.test) } 测试(){ console.log(this.socket);//未定义日志 } } 问题是为什么this.socket返

每当新用户连接到socket.io时,事件处理程序就会为该用户创建一个名为Events的新类

const eventHandler=socket=>{
新事件(socket);
};
事件构造函数将其套接字设置为创建时给定的套接字

类事件{
构造函数(套接字){
this.socket=socket;
this.socket.on('test',this.test)
}
测试(){
console.log(this.socket);//未定义日志
}
}

问题是为什么
this.socket
返回未定义?我想我错过了socket.io中的某些东西是如何工作的,非常感谢您的帮助

我得到了自己的答案,它实际上与socket.io无关,而是与这个如何工作有关,进一步阅读: