Perfection Kills

by kangax

Exploring Javascript by example

We don’t need no stinkin’ “new”

August 21st, 2007

There seems to be a bit of confusion among people not too familiar with Scriptaculous library. I often hear questions like “Why is new Effect.BlindDown('myElement') is not working? Am I not passing myElement correctly?”. No, the situation is much simpler.

As of 1.7.1 Scriptaculous has 6 Core Effects:

All of the core effects should be INSTANTIATED. This means that we use “new” keyword in front of them:

new Effect.Opacity('myElement');
new Effect.Move('myElement');

Even though the correct syntax is clearly stated in wiki, it is sometimes not obvious and could be easily missed. These kind of things could make beginners bang their head against the wall for hours.

On the other hand, there is an extensive set of Combination effects:

These do NOT need “new” keyword and essentially are just static methods of Effect object:

Effect.Shrink('myElement');
Effect.SlideDown('myElement');

I hope this clears all the confusion

Categories: Script.aculo.us

Comments (6)

  1. Gravatar

    Moris said on Nov 13, 2007 @ 12:14

    Cool.
    [URL=http://mercedes-350m.caldwelltoyota.cn#] mercedes 350m [/URL]
    http://mercedes-350m.caldwelltoyota.cn mercedes 350m

  2. Gravatar

    Valerios said on Jan 16, 2008 @ 0:12

    interesting

  3. Gravatar

    Konstantinos said on Jan 16, 2008 @ 9:39

    Cool!

  4. Gravatar

    Ioannis said on Jan 20, 2008 @ 11:35

    Interesting…

  5. Gravatar

    Sotirios said on Jan 23, 2008 @ 17:58

    Interesting…

  6. Gravatar

    Anaklets said on Jan 25, 2008 @ 3:13

    Cool…

Trackbacks

Leave a Comment

Please, don't forget to escape your input (<, > and &). Wrap code sections with <pre>

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>