From 212b7aa950a9cb226ed4e8c18aa35897273bd515 Mon Sep 17 00:00:00 2001 From: 1sm <31946591+1sm23@users.noreply.github.com> Date: Tue, 27 Apr 2021 23:35:46 +0800 Subject: Update /web/javascript/reference/operators/this, zh-CN (#667) fix: zh-cn 'this' typographical errors and translation --- .../web/javascript/reference/operators/this/index.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/operators/this') diff --git a/files/zh-cn/web/javascript/reference/operators/this/index.html b/files/zh-cn/web/javascript/reference/operators/this/index.html index a3378079ac..0962ff2a6e 100644 --- a/files/zh-cn/web/javascript/reference/operators/this/index.html +++ b/files/zh-cn/web/javascript/reference/operators/this/index.html @@ -129,19 +129,20 @@ new Bad(); // ReferenceError

函数上下文中的 this

-
// An object can be passed as the first argument to call or apply and this will be bound to it.
+
+// 对象可以作为 bind 或 apply 的第一个参数传递,并且该参数将绑定到该对象。
 var obj = {a: 'Custom'};
 
-// We declare a variable and the variable is assigned to the global window as its property.
+// 声明一个变量,并将该变量作为全局对象 window 的属性。
 var a = 'Global';
 
 function whatsThis() {
-  return this.a;  // The value of this is dependent on how the function is called
+  return this.a;  // this 的值取决于函数被调用的方式
 }
 
-whatsThis();          // 'Global' as this in the function isn't set, so it defaults to the global/window object
-whatsThis.call(obj);  // 'Custom' as this in the function is set to obj
-whatsThis.apply(obj); // 'Custom' as this in the function is set to obj
+whatsThis();          // 'Global' 因为在这个函数中 this 没有被设定,所以它默认为 全局/ window 对象
+whatsThis.call(obj);  // 'Custom' 因为函数中的 this 被设置为obj
+whatsThis.apply(obj); // 'Custom' 因为函数中的 this 被设置为obj
 

this 和对象转换

-- cgit v1.2.3-54-g00ecf