About the meal maker's 'this'

in the snippet of the project,
why
“get appetizers(){
return this._courses.appetizers;
},”
and the other part
" get courses(){
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts}}
"
why in the second snippet “this” is not followed by courses??
I do not know whtether I describe the problem clearly, Thanks anyway.
const menu = {
_courses: {
appetizers: ,
mains: ,
desserts:
},

get appetizers(){
return this._courses.appetizers;
},
set appetizers(appetizerInput){
this._courses.appetizers = appetizerInput;
},
get mains(){
return this._courses.mains;
},
set mains(mainsInput){
this._courses.mains = mainsInput;
},
get desserts(){
return this._courses.desserts;
},
set desserts(dessertInput){
this._courses.desserts = dessertInput;
},

get courses(){
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts

Sorry it took so long to get a reply!

The reason is because the getter methods for appetizers, mains and desserts have to access the object courses where the information is stored. So:

get appetizers() {
   return this._courses.appetizers;

What the return statement is doing is using this to access the properties of the object it belongs to, the it uses dot notation ._courses to access the object courses, and dot notation one more time with .appetizers to access the property appetizers inside courses.

Here:

get courses() {
   return
   {
      appetizers: this.appetizers,
      mains: this.appetizers,
      desserts: this.desserts
   }
}
  • First, remember that getter methods are meant to access the properties they are named after. So get courses() will accessing the property courses from the start.
  • Secondly, notice that we want to return an object, so the return statement has { } to create that object.
  • Finally, the object created for the return will have three properties matching the ones we want to return from courses, so they are defined as such, and because the getting is already accessing courses, you only need to use dot notation once to get to courses properties.

I find it useful to think about this like a folder structure. You have your folder courses, and inside are three folders appetizers, mains, and desserts. And inside each of those folders you find the array with the information stored in it.

If you found yourself in front of folder courses, you would open folder courses, and then open folder mains (for example) before to find the dishes stored inside mains. And this is why you have to use double dot notation to get to the data. Because you have to go “two levels” in, so to speak. I hope this helps! :+1: