So the best way to do this is with a w / function scope.
function myFunc(){
this.nameRoot = "my object";
}
then you can do something like:
var func = new myFunc();
func.sub = new myFunc();
func.sub.nameRoot = "my sub object";
Obviously, there are more reasonable ways to do this (for example, pass a name through function parameters), but this is a common template.
source
share