Perfection Kills

by kangax

Exploring Javascript by example

← back 211 words

We don't need no stinkin' "new"

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:


I hope this clears all the confusion.

Did you like this? Donations are welcome

comments powered by Disqus