在函数中保存旧参数



我创建了一个即时通讯工具。我的函数cliked(thread(允许我单击讨论并查看此讨论。用户不能同时打开超过 2 个聊天窗口。 因此,当打开两个聊天窗口(this.threadService.windows.length === 2(时,我必须关闭第一个窗口才能显示新窗口。

然后,我必须将第一个窗口保存在变量中,以便将其作为我的函数closeOldThread(oldThread(的参数输入

clicked(thread: Thread): void {
this.newWindow = true;
let oldThread: Thread;
if(this.threadService.windows.length === 2) {
this.closeOldThread(oldThread);
}
if (!this.thread.isOpen) {
thread = this.chatService.openThread(thread);
this.chatService.setCurrentThread(thread);
this.thread.isOpen = true;
}
oldThread = thread;
}

////

closeOldThread(thread: Thread): void {
let index = this.threadService.windows.indexOf(thread);
this.threadService.windows.splice(index, 1);
this.thread.isOpen = false;
this.newUser = false;
this.newWindow = false;
}

这可能吗? 因为就我而言,oldThread是未定义的。

clicked(thread: Thread): void {
this.newWindow = true;
if(this.threadService.windows.length === 2) {
// get the previously opened chat window
let oldThread = this.threadService.windows[0];            
this.closeOldThread(oldThread);
}
if (!this.thread.isOpen) {
thread = this.chatService.openThread(thread);
this.chatService.setCurrentThread(thread);
this.thread.isOpen = true;
}
}

最新更新