通常當我們使用this
時,它指的是類。我該如何使這個指的是函數中的類?
但是在這種情況下,this
是dataChannel
,我怎樣才能讓this
再次指VideoService
?謝謝
export class VideoService {
dataChannel:any;
setupPeerConnection() {
this.dataChannel.onopen = this.dataChannelStateChanged;
}
dataChannelStateChanged() {
// here this = dataChannel, how can I let this = VideoService
console.log(this);
}
}
謝謝sfsq! –