mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
Merge pull request #69 from lmk123/patch-4
事件处理函数中的 this 并不是指向全局对象,而是指向绑定事件的节点元素
This commit is contained in:
commit
bdadd3e2d7
@ -571,7 +571,7 @@ var handler = {
|
||||
};
|
||||
```
|
||||
|
||||
上面代码的init方法中,使用了箭头函数,这导致this绑定handler对象,否则回调函数运行时,this.doSomething这一行会报错,因为此时this指向全局对象。
|
||||
上面代码的init方法中,使用了箭头函数,这导致this绑定handler对象,否则回调函数运行时,this.doSomething这一行会报错,因为此时this指向document对象。
|
||||
|
||||
由于this在箭头函数中被绑定,所以不能用call()、apply()、bind()这些方法去改变this的指向。
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user