I often use this structure:
var example = (function () { function privateFn2 () { ... } function privateFn1 () { ... } return { publicMethod1: function () {... }, publicMethod2: function () {... } }; }());
I want to know the following: If privateFn1 is the only function / method that calls privateFn2, is it considered best practice to set it up as follows?
EDITED for clarity
var example = (function () { function privateFn1() { function privateFn2() { } ... privateFn2(); } return { publicMethod1: function () {... }, publicMethod2: function () {... } }; }());
This, of course, is a simplified example. The problem is that I have many private functions, and I wonder if nesting is good or bad. I admit that this is most likely a matter of preference, but any advice would be greatly appreciated.
Thanks.
javascript function nested
Nick
source share