On Dec 24, 3:05 pm, Garrett Smith <[email protected]> wrote:

> I rather have it one way or the other. e.g.
>
>   makePoint(x, y);
>
>  - OR -
>
>   new Point(x, y);
>
> I just don't like seeing any extra if/else in the code. I also don't
> want to handle the case where somebody might be relying on an anomaly
> of calling the constructor as a function call.

If defensive programming isn't necessary, of course. But since JS
can't statically enforce such things it may be necessary to do so.

> > Plus when using the constructor pattern, Java style "super" calls can
> > be emulated with apply()
>
> When Point has a superclass or when Point *is* the superclass?

In general I mean vs the Object.create() pattern.

> Generally I keep the constructors private and only use factories and
> return an interface object. Doing that avoids having to deal with
> constructor issues.

Just seems like more boilerplate when building a hierarchy as you'd
have to manually set the constructor property and fidget with
prototypes to make instanceof  and the constructor property work as
expected. But I guess if its not expected to be used that way it
wouldn't matter.

-- 
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