1
0
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:
Ruan YiFeng 2015-07-23 21:19:54 +08:00
commit bdadd3e2d7

View File

@ -571,7 +571,7 @@ var handler = {
};
```
上面代码的init方法中使用了箭头函数这导致this绑定handler对象否则回调函数运行时this.doSomething这一行会报错因为此时this指向全局对象。
上面代码的init方法中使用了箭头函数这导致this绑定handler对象否则回调函数运行时this.doSomething这一行会报错因为此时this指向document对象。
由于this在箭头函数中被绑定所以不能用call()、apply()、bind()这些方法去改变this的指向。