跳轉到內容

JavaScript/詞彙表

來自華夏公益教科書



我們試圖在使用技術術語時保持華夏公益教科書的一致性。因此,這裡有一個簡短的詞彙表。

物件 物件是一個包含鍵值對的關聯陣列。這些對被稱為屬性。所有資料型別都源自物件 - 除原始資料型別外。
屬性 物件的一部分鍵值對。鍵部分是字串或符號,值部分是任何型別的值。
點表示法 使用點標識物件屬性的語法:myObject.propertyKey
方括號表示法 使用方括號標識物件屬性的語法:myObject["propertyKey"]
花括號表示法 使用 { } '字面' 表達物件的語法:const myObject = {age: 39}
函式 函式是由關鍵字 function、可選名稱、開括號、可選引數和閉括號引入的程式碼塊。
function greeting(person) {
  return "Hello " + person;
};

上面的函式是有名函式。如果您省略函式名稱,我們將其稱為匿名函式。在這種情況下,可以使用箭頭語法 => 作為替代語法。

function (person) { // no function name
  return "Hello " + person;
};

// 'arrow' syntax. Here is only the definition of the function.
// It is not called, hence not running.
(person) => {
  return "Hello " + person;
};
// or:
(person) => {return "Hello " + person};

// assign the definition to a variable to be able to call it.
let x = (person) => {return "Hello " + person};
// ... and execute the anonymous function by calling the variable
// that points to it: x(...)
alert(  x("Mike")  );

// interesting:
alert(x);

// execute an anonymous function directly
((person) => {
  alert("Hello " + person);
})("Mike");
方法 方法是儲存為物件鍵值對的函式。鍵代表方法名稱,值代表方法體。可以使用以下語法定義和訪問方法
let person = {
    firstName: "Tarek",
    city : "Kairo",
    show : function() {
             return this.firstName +
             " lives in " +
             this.city;
           },
};
alert(person.show());
回撥函式 作為引數傳遞給另一個函式的函式。
控制檯 每個瀏覽器都包含一個視窗,用於顯示內部資訊。它被稱為控制檯,通常不會開啟。在大多數瀏覽器中,您可以透過功能鍵 F12 開啟控制檯。
陣列中的單個值。與 '元素' 相同。
元素 陣列中的單個值。與 '項' 相同。
引數 定義函式時,可以在其簽名中宣告變數,例如:function f(param1, param2)。這些變數稱為引數
引數 呼叫函式時,可以宣告要處理的變數,例如:f(arg1, arg2)。這些變數稱為引數。引數替換了在函式定義期間使用的引數。
華夏公益教科書