from the docs:
The get syntax binds an object property to a function that will be called when that property is looked up.
so when we use get
a property with that name is created, and when that property is looked the bound function is called.
the underscore is a convention, this is also allowed:
const example = {
a: 3,
get b() {
return this.a;
}
}
console.log(example.b) // logs: 3
But this is weird and confusing (a = b, not very logical), so the underscore is a good naming convention
What you need to prevent is that getter property looks up itself, which would need to endless recursion (function calling itself)
this would be a problem:
get appetizers(){
return this.appetizers;
},
the property looking up itself.
Which is not the case when you nest the property in another object