I'm trying to create an Object containing other Objects and functions, in a prototype, the relevant part is the UI prototype;
var fChat = function() {
this.debug = true;
};
fChat.prototype = {
constructor: fChat,
Log: function(str){
if(this.debug){
console.log(str);
}
},
UI: {
Login: {
Show: function(){
this.Log("UI.Login.Show()");
}
}
}
};
var fChatInstance = new fChat();
fChatInstance.UI.Login.Show();
When i call fChatInstance.UI.Login.Show() It give me an error:
Uncaught TypeError: this.Log is not a function
Is that because by using this is on another scope?
Usually i do var self = this;at the start of a prototype, but i don't know how I can do that by using an Object prototype.
thisis the object{ Show: function() { /*...*/ } }. You can figure that out by debugging withinShowand checkingthisor by doingconsole.log(this);withinShowfChathas it's own singletons ofLog,UI? Seems like all of that stuff should be abstracted out into their own unit-of-work "classes"Loginclass and then pass in aLoggerclass instance in the constructor. Right now thatfChatclass has multiple responsibilities.