On 11/3/06, Jason Bunting <[EMAIL PROTECTED]> wrote:
>
> (Forgot to reply all)
>
> > -----Original Message-----
> > From: [email protected] [mailto:[EMAIL PROTECTED] On
> > Behalf Of [EMAIL PROTECTED]
> > Sent: Friday, November 03, 2006 12:52 PM
> > To: MochiKit
> > Subject: [mochikit] Visual: When to use 'new' and when not to?
> >
> >
> > Hello all,
> >
> > I'm trying out MochiKit.Visual, and ran across an issue. I was trying
> > to use Highlight() and it just wasn't working (errors about __init__
> > not being defined). I eventually figured out that I had to do:
> >
> > new Highlight(src);
> >
> > But I've been able to use other visual effects (puff, fade. several
> > others) without explicitly using 'new'. Is this just a temporary
> > inconstancy in the API, a bug in Firefox (1.5) or something that I'm
> > missing in the documentation?
>
> It is subtle, but anything in the documentation that is PascalCased is a
> class, and thus needs to be instantiated, anything camelCased is a function
> and you can simply use it. This gets people all the time, myself included. I
> can't speculate as to the reasons for all of this and will defer that to
> someone that knows.

There's no good reason for it other than heritage. Scriptaculous and
Prototype make you use new all the time for no good reason whatsoever,
and that's inherited in the port. It's probably something we should
fix before that stuff goes out the door.

It's not too hard to make it work.. e.g. you can do something like
this in the constructor:

if (!(this instanceof arguments.callee)) {
    return new arguments.callee(arg1, arg2, argN);
}

Then that constructor can be used with or without the new operator.
Unfortunately there is no apply or call for the new operator so the
arguments have to be listed manually.. either that, or more trickery
has to ensue, like using a two-phase construction/initialization.

-bob

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to