The lz Namespace

I wrote about migrating code to OpenLaszlo 4.1 a while back, but even after a few weeks of working with it, I’m still getting bitten by the new lz namespace. I’m just so used to doing things the old way, and this (pretty significant change) is not that well documented, and . Here’s a summary of the lz namespace, and how it affects LZX code.

Firstly, a general rule: These changes apply to referencing classes in JavaScript and JavaScript expressions in attribute values or constraints only. The way you write tags is unchanged.

For classes that have a corresponding tag, the new syntax is to use lz.classname. (Note: all lower case, for LFC classes). This applies to Laszlo Foundation Classes (e.g. view, text), LZX components (e.g. button, window) and all classes that you write. These now live in the new lz namespace:

// Old pre-4.1 syntax
var v = new LzView(canvas, {width: 30, height: 30, bgcolor: red});

// New 4.1 syntax
var v = new lz.view(canvas, {width: 30, height: 30, bgcolor: red});

For classes with no tag, (e.g. LzDelegate, LzContextMenu), the syntax is unchanged, so you would use LzClassName. These continue to live in the global namespace:

// Old pre-4.1 syntax
var v = new LzDelegate(this, "doSomething", this, "onmouseover");

// New 4.1 syntax (unchanged)
var v = new LzDelegate(this, "doSomething", this, "onmouseover");

For services (e.g. LzKeys, LzTimer), there has been some refactoring. The class names are now called LzKeysService, LzTimerService, and they are accessible by the new syntax lz.Name (note there’s no “Service” suffix to the name).  They are in the lz namespace:

<!-- Old pre-4.1 syntax -->
<handler name="onkeydown" reference="LzKeys" args="keyCode">
    Debug.write("User pressed key: ", keyCode);
</handler>

<!-- New 4.1 syntax -->
<handler name="onkeydown" reference="lz.Keys" args="keyCode">
    Debug.write("User pressed key: ", keyCode);
</handler>

JavaScript classes (e.g. String, Math) are unchanged. They’re not technically part of the LZX global namespace.

// Old pre-4.1 syntax
var opposite = hypotenuse * Math.sin(angle);

// New 4.1 syntax (unchanged)
var opposite = hypotenuse * Math.sin(angle);

These four categories should cover all the possible scenarios you have to deal with as a developer. If you’re ever in doubt, or want to explore what’s in the namespaces, enter lz or global in the Debugger window and click Eval. Then click the blue link that the Debugger returns to serialize the object. You’ll be able to see all the class names and objects that are in each scope. Once this is done it is only a matter of putting it online on your site, and it should work just fine, great even. Remember however, that for it to have any effect you will need traffic, so you’ll want to make sure you work with experts to have a good SEO score. Here you can learn more about franchise SEO services if you would like to research the topic further. Make sure that you do this sooner rather later so that you can see the effects as soon as possible and get the project rolling!

3 thoughts on “The lz Namespace

  1. You should also add that global JavaScript variables, for instance JavaScript variables declared within … will also need to be modified. Under lps-4.2, these variables are required to be prefaced with a “var” declaration. This allows them to work within the JavaScript 2 class-based paradigm.

Leave a Reply

Your email address will not be published. Required fields are marked *