TIL 04 | JS property & method


JavaScriptを構成するほとんどのものが対象です.また,このオブジェクトは,データを表すプロセスと動作を表す方法からなる集合である.

米と大豆の性質と方法


PropertyとMethodについての簡単で面白い比喩があり、添付されています.
米と大豆が対象なら
各オブジェクトの固有の色はpropertyです.
そして、食べる行為が一つの方法になります.

出典:ディスカッション.codecademy.com/t/what-does-it-mean-by-an-instance-of-a-data-type/489754/9

属性値のアクセス方法

  • 句号(.)符号
  • 角括弧([文字列])記号
  •   Propertyキーは有効なJavaScript名と予約語ですか?     Y-両方の記号を使用可能   N-かっこ記号のみサポート

    シンボルの使用例

    var person = {
      'first-name': 'Minsu',
      'last-name': 'Lee',
      gender: 'male',
      1: 10
    };
    
    console.log(person);
    
    console.log(person.first-name);    // NaN: undefined-undefined
    console.log(person[first-name]);   // ReferenceError: first is not defined
    console.log(person['first-name']); // 'Minsu'
    
    console.log(person.gender);    // 'male'
    console.log(person[gender]);   // ReferenceError: gender is not defined
    console.log(person['gender']); // 'male'
    
    console.log(person['1']); // 10
    console.log(person[1]);   // 10 : person[1] -> person['1']
    console.log(person.1);    // SyntaxError

    ⑪メソッドの使用方法


    次の方法でメソッドを呼び出して使用できます.
    ポイント
    メソッド名
    かっこ'example string'.methodName() console.log()参考資料:
    https://poiemaweb.com/
    https://www.codecademy.com/