On Jan 1, 1:15 am, אריה גלזר <[email protected]> wrote:
> Maybe it's because of the lack of real examples, but I failed to understand
> the need for so many closures:
> 1. Why do you create a list of private methods that even the inner module
> cannot access?
> 2. Why make the constructor private?
> 3. Why wrap the public with a closure? why not simply return it? you don't
> define anything within it

To answer:

#1. The private methods *are* accessible.  Just un-comment the
console.log, within private.init and you will see it is accessible.
This then sort of answers:

#3:  $public is wrapped with a closure so that, before return $public,
code can be executed, such as $private.init().  Indeed, I see this as
being a nice way to obviate a "temporal dependence", through use of
the "template method" pattern: initialization should occur before the
public interface is returned.

Returning to your point #2, there is no constructor.  Do you mean why
is the init method private?  Well, there is no need for it to be
public, is there?  Do you want users of the module to be able to call
init over and over again, whenever they please?

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to