From c0b0eed507cb1a8e34d319218f03c839cf6b1cfa Mon Sep 17 00:00:00 2001 From: Milk Lee Date: Thu, 23 Jul 2015 12:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=B8=AD=E7=9A=84=20this=20=E5=B9=B6=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E6=8C=87=E5=90=91=E5=85=A8=E5=B1=80=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=EF=BC=8C=E8=80=8C=E6=98=AF=E6=8C=87=E5=90=91=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84=E8=8A=82=E7=82=B9=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```js document.addEventListener('click',function(){console.log(this === document)}); // true ``` 从上面这段代码可以看出,事件处理函数里的 `this` 并不是指向 `window` 对象。如果你所说的“全局对象”并不是指 `window` 对象,我也觉得应该阐明这里的“全局对象”到底是指什么,以免产生歧义 --- docs/function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/function.md b/docs/function.md index 0c35f8c..f4fe970 100644 --- a/docs/function.md +++ b/docs/function.md @@ -571,7 +571,7 @@ var handler = { }; ``` -上面代码的init方法中,使用了箭头函数,这导致this绑定handler对象,否则回调函数运行时,this.doSomething这一行会报错,因为此时this指向全局对象。 +上面代码的init方法中,使用了箭头函数,这导致this绑定handler对象,否则回调函数运行时,this.doSomething这一行会报错,因为此时this指向document对象。 由于this在箭头函数中被绑定,所以不能用call()、apply()、bind()这些方法去改变this的指向。