From f45e9e070c93ebbd83d488bdd775987a4d75c201 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:08 +0800 Subject: fix yari h2m dry run errors --- .../zh-tw/web/javascript/reference/operators/this/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/operators/this/index.html') diff --git a/files/zh-tw/web/javascript/reference/operators/this/index.html b/files/zh-tw/web/javascript/reference/operators/this/index.html index 9c99fb42f2..1dd3d43d4e 100644 --- a/files/zh-tw/web/javascript/reference/operators/this/index.html +++ b/files/zh-tw/web/javascript/reference/operators/this/index.html @@ -65,8 +65,8 @@ f2() === undefined; //true

所以在嚴格模式下,如果 this 沒有定義到執行環境內,其預設值就會是 undefined

-
-

在第二個例子裡面,this 應為 undefined,因為 f2 是直接被呼叫,而不是在其為某個物件的方法或屬性的情況下(例如 window.f2())被直接呼叫。某些瀏覽器首次支援嚴格模式時沒導入這個特徵,它們會因此錯誤的回傳 window 物件。

+
+

備註:在第二個例子裡面,this 應為 undefined,因為 f2 是直接被呼叫,而不是在其為某個物件的方法或屬性的情況下(例如 window.f2())被直接呼叫。某些瀏覽器首次支援嚴格模式時沒導入這個特徵,它們會因此錯誤的回傳 window 物件。

要從某個語境訪問另一個 this 語境的值,請使用 callapply:

@@ -138,8 +138,8 @@ console.log(o.f(), o.g(), o.h()); // 37, azerty, azerty var foo = (() => this); console.log(foo() === globalObject); // true -
-

註:如果這參數被傳遞給箭頭函式的 call, bind, apply 調用,該參數會被忽略。你仍然可以將參數預先調用到call,但第一個參數(thisArg)必須設置為空。

+
+

備註:如果這參數被傳遞給箭頭函式的 call, bind, apply 調用,該參數會被忽略。你仍然可以將參數預先調用到call,但第一個參數(thisArg)必須設置為空。

// 作為物件的方法呼叫
@@ -253,8 +253,8 @@ console.log(o.average, o.sum); // logs 2, 6
 
 

若函式以建構子的身份呼叫(使用 new 關鍵字) this 會和被建構的新物件綁定。

-
-

建構子預設透過 this 回傳該物件的參照,但它其實能回傳其他物件。如果回傳值不是物件的話,就會回傳 this 這個物件。

+
+

備註:建構子預設透過 this 回傳該物件的參照,但它其實能回傳其他物件。如果回傳值不是物件的話,就會回傳 this 這個物件。

/*
-- 
cgit v1.2.3-54-g00ecf