Mootools classes have an initialize()
method that's called when a new object is instantiated.
It seems that setup()
is a commonly used method as well.
Most classes I've observed call this.setup()
from initialize()
and nowhere else, which has left me wondering:
What's the purpose of setup()
? Why not just put the setup()
code in initialize()
? When does it make sense to use a setup()
method?
There is no benefit whatsoever in using a setup/build/whatever function that is only called from the initialize function of a mootools Class.
I guess the distinction comes from languages where you don't have variable function arguments but rather overload function names with different sets of arguments. Like Java.
In Java this makes perfect sense. When you have multiple constructors that differ in the arguments they accept, then you handle the argument specific operations in your constructor and the common stuff, that every constructor needs to call in a method that is called by all constructors.
Personally I don't make this distinction in my mootools Classes, but rather only outsource functionality in its own function, if there is need to reuse the code from another function.
Don't get confused by setup functions, there is no hidden power to them.