Meal Maker

let menu = {
    _courses:{
        _main:["kj"]
        ,set main(newMain){
            this._courses._main=newMain;
        }
    }
};
menu._courses.main="pa";
Uncaught TypeError: Cannot set property '_main' of undefined

It appears that I have made a typing mistake, but I can not detect it! any help please?

why not put the comma at the end of the line:

        _main:["kj"],

so much more readable. Well, this is the the courses object:

let menu = {
    _courses:{
        _main:["kj"],
        set main(newMain){
           console.log(this);
           // this._courses._main=newMain;
        }
    }
};
menu._courses.main="pa";

so to get _main property, you can just do this._main.

or you could move the setter to the menu object. This simplifies access to the nested property

1 Like

Oh! Thank you so much :smiley: