[Laszlo-dev] init vs oninit vs super.init
Elliot Winard
ewinard at laszlosystems.com
Tue Aug 7 12:08:05 PDT 2007
Hrm. Actually, subclass init method gets called. Superclass init
method doesn't get called unless the subclass calls superclass.init().
The below example is a bit misleading because brusselssprouts calls
super.init() before Debug.outputting.
-e
---=---===-------
Elliot Winard
Sr. Software Engineer
Webtop Team
---=---===-------
On Tue, Aug 7, 2007 at 2:45 PM, Benjamin Shine wrote:
> Bret and I were going through a code change and wanted a clarification
> on what order things were expected to happen:
>
> <canvas>
> <class name="cabbage">
> <method name="init">
> // called FIRST
> Debug.write("cabbage.init (method name=init) on %w", this);
> this.setAttribute("deliciousness", 0.35);
> </method>
> <handler name="oninit">
> // called SECOND
> Debug.write("cabbage.oninit (handler name=oninit) on %w", this);
> </handler>
> </class>
>
> <class name="brusselssprout" extends="cabbage">
> <method name="init">
> super.init(); // calls method name="init" on cabbage
> Debug.write("brusselssprout.oninit method on %w, deliciousness is
> %f", this, this.deliciousness);
> </method>
> <handler name="oninit">
> // called *after* cabbage's oninit handler
> Debug.write("brusselssprout.oninit handler on %w, deliciousness is
> %f", this, this.deliciousness);
> </handler>
> </class>
>
> <cabbage id="cabby" />
> <brusselssprout id="sprouty" />\
> </canvas>
>
> This produces the following output:
> cabbage.init (method name=init) on #cabby
> cabbage.oninit (handler name=oninit) on #cabby
> cabbage.init (method name=init) on #sprouty
> brusselssprout.oninit method on #sprouty, deliciousness is 0.350000
> cabbage.oninit (handler name=oninit) on #sprouty
> brusselssprout.oninit handler on #sprouty, deliciousness is 0.350000
>
>
> ...which is just what I expect: superclass methods called before
> sublcass methods, method name="init" called before oninit handler.
>
> Is this the guaranteed order of execution?
>
> -ben
More information about the Laszlo-dev
mailing list