Day-8 Method, this
1244 ワード
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.
メソッドのvalueをownerオブジェクトのプロパティとして保存する場合は、次の手順に従います.キーワードを使用します.
使用する前に、この値はpropertyによって定義/宣言されていないため、ower objectによってundefined valueとして表されます.
コードチャレンジ终了!!
Recap:
Objects can holds different typs of data
objects can hold object inside object (similarities with array)
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)
Reference
この問題について(Day-8 Method, this), 我々は、より多くの情報をここで見つけました https://velog.io/@ssovival/Day-8-Method-thisテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol