I have been mauling over this for while now, and wonder if anyone could point me in the right direction.
I have the following object definition:
var foo=function(){};
foo.prototype={
foo1:function(){},
baz:{
baz1:function(){}
},
bar:function(){
function privateFunc1(){}
function privateFunc2(){}
return {
bar1:function(){
//do something using privateFunc1
//return the result
}
};
}
};
var foobar = new foo();
Now, to access the baz1 sub-method of the baz method, I can do foobar.baz.baz1()
But to access the bar1 sub-method of the bar method, I have to do foobar.bar().bar1() (Notice the extra parens after bar)
Is there a way of defining the foo object so that I can call bar1 using foobar.bar.bar1() (Notice, no extra parens), But still keep the use of private functions privateFunc1 and privateFunc2 within the bar method.
Also, please note that I cannot make bar a self-executing function because it depends on mutable properties of the foo object, which may change after the function has self-executed.
Hope the question was clear enough... thanks in advance.