On Fri, 2010-12-17 at 06:53 -0800, qwertypants wrote:
> I'd like to find the best way to do so.
There's no one accepted best way. There are two broad approaches:
prototypes and closures; they both have positive and negative points.
There are naturally a *lot* of variations within each type, and also a
lot of bad code (common in tutorials) which inappropriately mixes the
paradigms.
Here's a summary I posted to SO of some of the main issues:
http://stackoverflow.com/questions/1595611/js/1598077#1598077
> Am I going to have to create a function to create my objects
You can certainly get away without it, but most people use some sort of
shortcut.
> Is there a more efficient way of doing this?
Well what you have there is purely a data object, holding only
instance-specific values.
So the performance differences between using prototypes and closures are moot,
there are no methods to share or inherit.
Since you have returned a new object rather than using `this`, an instance of
your
`Circle` won't respond to `instanceof Circle`.
--
And Clover
mailto:[email protected] http://www.doxdesk.com
skype:uknrbobince gtalk:[email protected]
--
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]