var O = {
elements: {
main: function() { return jQuery("#main"); },
footer: function() { return jQuery("#footer"); }
},
main: function(html) {
return (this.elements.main());
},
style: {
setMaincolor: function() {
// TypeError: Cannot call method 'main' of undefined
return (this.elements.main());
}
}
};
so; I’m O.style Object parents Objects ????
O.style.setMaincolor() // TypeError: Cannot call method 'main' of undefined
O.main() // [<div id="main"></div>]
setMaincolor method return this to O Object
thisrefers to the object on which the method was invoked.main()is invoked on theOobject, sothisis a reference toO. Thereforethis.elements === O.elements.setMaincolor()is invoked on thestyleobject, sothiswill be a reference toO.style, which does not have an.elementsproperty.