求解释一下下面几句代码:
wr.onopen = this._onWebRTCOpen.bind(this);
wr.onclose = this._onWebRTCClose.bind(this);
wr.onmessage = this._onWebRTCMessage.bind(this);
wr.onerror = this._onWebRTCError.bind(this);
解释一下这几句代码的作用即可,THX!
求解释一下下面几句代码:
wr.onopen = this._onWebRTCOpen.bind(this);
wr.onclose = this._onWebRTCClose.bind(this);
wr.onmessage = this._onWebRTCMessage.bind(this);
wr.onerror = this._onWebRTCError.bind(this);
解释一下这几句代码的作用即可,THX!
10 回答11.3k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.2k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.4k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
理解
this
在function
里指向的是谁!直接把一个函数赋值到变量上,执行的时候即使你这个function原本是一个对象的成员方法,
this
也不会指向原来的对象去。bind
帮你处理了这个问题。所以你来理解的是bind
是什么鬼!https://developer.mozilla.org...bind可以这么理解就是返回了一个新的方法,这个方法在执行的时候,执行的主题还是原来方法的内容,只是
this
指向了bind
时绑定的对象上。这不算
es6
知识点,下次遇到问题,建议先看是不是有啥关键字什么方法没见过的,先搜一搜,比如这里的bind