How can I make this refers to the class in the function?

Viewed 85

Usually when we use this, it refers to the class.

But in this case, this is dataChannel, how can I let this refers to VideoService again? Thanks

export class VideoService {
    dataChannel:any;

    setupPeerConnection() {
        this.dataChannel.onopen = this.dataChannelStateChanged;
    }

    dataChannelStateChanged() {
        // here this = dataChannel, how can I let this = VideoService
        console.log(this); 
    }
}
2 Answers
Related