Sunday, March 05, 2006

scope in OpenLaszlo

I have problems with scope in OpenLaszlo. I do not understand. A Google search on "OpenLaszlo scope" is no help. So I'm reduced to running little tests.

This code does nothing:

<canvas debug="true">
<method name="createIt">
var it = "Buffy";
</method>
<method name="useIt">
Debug.write(it);
</method>
</canvas>


It does nothing because the methods are never called. Good, I understand this.

<canvas debug="true" oninit="createIt(); useIt()">
<method name="createIt">
var it = "Buffy";
</method>
<method name="useIt">
Debug.write(it);
</method>
</canvas>


This code produces a warning in the debugger window:
"WARNING: test_scope.lzx:7: reference to undefined variable 'it'
«undefined»"

Good, that is what I was expecting. The variable "it" was declared in createIt and is out of scope in useIt.


<canvas debug="true" oninit="createIt(); useIt()">
<method name="createIt">
it = "Buffy";
</method>
<method name="useIt">
Debug.write(it);
</method>
</canvas>


The debugger window reads "Buffy". In other words, "it" is not out of scope. This makes me weep. It is probably another one of those weird javascript things, and I do not understand. Is "it" global because I didn't use "var"? *sigh*

0 Comments:

Post a Comment

<< Home