bot-node-sdk icon indicating copy to clipboard operation
bot-node-sdk copied to clipboard

[Feature] ws回调函数的this绑定问题

Open Gk0Wk opened this issue 2 years ago • 1 comments

版本:2.9.1

复现方式:

import { createWebsocket } from 'qq-guild-bot';
class Test {
    constructor(ws: any) {
        ws.on('READY', this.test);
    }
    test() {
        console.log(this);
    }
}
const test = new Test(createWebsocket(/* 配置文件略 */));
test.test();

输出结果:Ready回调Test.test()输出的this为WebsocketClient,而非test实例。


所以是不是应该改成绑定为对应的类实例会好一些?因为一些时候需要将功能封装,不这样的话会很难受。

Gk0Wk avatar Apr 29 '22 03:04 Gk0Wk