在这种情况下,我不知道如何保留对聊天类的引用。解决方法是什么?
class chat {
private self: chat;
public currentUsers: any = ko.observableArray();
constructor(public chatService: any) {
this.self = this;
chatService.client.receiveUsers = this.receiveUsers;
}
private receiveUsers(users: any): void {
//'this' has been changed to refer to the external caller context (chatService.client)
this.currentUsers(users);//fail
//property currentUsers does not exist on value of type 'Window'
self.currentUsers(users);//fail
//currentUsers does not exist in the current scope
currentUsers(users);//fail
//There's apparently no way to access anthing in this chat class from inside here?
}
}