Merge pull request #69 from lmk123/patch-4

事件处理函数中的 this 并不是指向全局对象,而是指向绑定事件的节点元素
This commit is contained in:
Ruan YiFeng
2015-07-23 21:19:54 +08:00
+1 -1
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的指向。