Day-8 Method, this


Method: this is function that stored as property
Method actions that can be performed on objects
Method stored in properties as function definitions.
this key word : In a method, 'this' refers to the owner object.
const sso = {
    firstName: 'Sso',
    lastName: 'Ahn',
    birthYear: 1992,
    job: 'director',
    friends: ['Michael', 'Peter', 'Steven'],
    hasDriverLicense: true, //boolean property(data type),

    // function (birthYear) {
    //     return 2037 - birthYear;
    // } this would not work because it is only declaration object method need to be expression!!

    calcAge: function () {
    console.log(this);
    return 2037 - this.birthYear; //this.birthYear means the birthYear property of this object.

} //sso object that "owns" the calcAge function

メソッドのvalueをownerオブジェクトのプロパティとして保存する場合は、次の手順に従います.キーワードを使用します.
使用する前に、この値はpropertyによって定義/宣言されていないため、ower objectによってundefined valueとして表されます.
コードチャレンジ终了!!
Recap:
Objects can holds different typs of data
objects can hold object inside object (similarities with array)