Sometime ago I heard that it was good practice to wrap your code in a big object to serve as a namespace in order to reduce global namespace cluttering and to facilitate library export, so I tried this.
var wrapper = {
foo: function(){
return 42;
},
bar: this.foo()
};
It fails, claiming that "foo is not defined". Calling methods before finishing the object declaration is probably bad, so I moved bar, and it worked.
var wrapper = {
foo: function(){
return 42;
},
};
wrapper.bar = wrapper.foo();
I feel that this can become kind of ugly, especially with nested namespaces and such, so are there any workarounds that don't make it hard to see all of the wrapper's members at once?