I'm creating some methods in the LayoutConstructor object:
function LayoutConstructor() {};
LayoutConstructor = {
buildNewsroom: function() {
this.newsroom.buildSidebar();
},
newsroom: {
buildSidebar: function() {
//some code...
//get the error: Cannot read property 'buildBoxWrapper' of undefined
this.general.buildBoxWrapper($(".sidebar .box-wrapper"));
}
},
general: {
// Build the box-wrapper
buildBoxWrapper: function(boxWrapper) {
//some code...
}
}
}
However, I get an error :
'Cannot read property 'buildBoxWrapper' of undefined'
when I try to run the method LayoutConstructor.newsroom.buildSidebar()
.
I also set the constructor :
function LayoutConstructor() {var self = this;}
and modify the buildSidebar
method:
buildSidebar: function(){
self.general.buildBoxWrapper($(".sidebar .box-wrapper"));
}
but it seems not help.
How does 'this' defined and how can I access other methods in the nested method?