perfection kills

Exploring prototype by example

We don’t need no stinkin’ “new”

August 21st, 2007 by kangax

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

  1. Gravatar

    Moris said:

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

  2. Gravatar

    Valerios said:

    interesting

  3. Gravatar

    Konstantinos said:

    Cool!

  4. Gravatar

    Ioannis said:

    Interesting...

  5. Gravatar

    Sotirios said:

    Interesting...

  6. Gravatar

    Anaklets said:

    Cool...

Trackbacks

Leave a Comment

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