I am finally asking this question as I have never actually found an answer. If I have a javascript object with a structure such as this:
var someObj = {
"categoryA" : {
"func1" : function(){},
"func2" : function(){},
},
"categoryB" : {
"func3" : function(){},
"func4" : function(){},
}
}
func4 wants to call func2. Do I have any way of calling it without saying someObj.func2()? It seems to me this is ugly since it is ensuring the application cannot be easily renamed and appears to be more tightly coupling the internal functions. Or is this just how it is typically organised and it is not seen as a problem?
You can always refractor your object declaration into something that looks like this :
It’s commonly called the “Module Pattern”.