Name

script (LzScript) — A block of JavaScript.

Synopsis

LZX: script
JavaScript: LzScript
Type: Class
Access: public
Topic: LZX.Basics
Declared in: WEB-INF/lps/lfc/views/LzScript.lzs

Description

The script element contains JavaScript code that is executed when the application is loaded. This element must be at the canvas level; that is, it cannot be contained within any subordinate tag. If the src attribute is present, it names a JavaScript file whose contents are compiled into the application.

In the example below, we add a method to the built-in Array class that will let us find the index of elements in an array. Note that Array.find uses === for finding, so that two objects that are similar will not be confused. This is why looking for {example: 'sneaky'} finds nothing, whereas looking for sneaky succeeds.

 <canvas debug="true" height="200" width="400">
   <script>
   <![CDATA[
     // Add a find method to Array
     Array.prototype.find = function ( what ) {
       for (i in this ) {
         if (this[i] === what) {
           return i;
         }       
       }
     }
     
     sneaky = {example: 'sneaky'};
     tryit = ['foo', 42, sneaky, Math.PI, false];
     
     Debug.write("42 is at: " + tryit.find(42));
     Debug.write("false is at: " + tryit.find(false));
     Debug.write("'bar' is at: " + tryit.find('bar'));        
     Debug.write("{example: 'sneaky'} is at: " + tryit.find({example: 'sneaky'}));        
     Debug.write("sneaky is at: " + tryit.find(sneaky));        
   ]]>
   </script>
 </canvas>
 

Development Note

An LzScript is the implementation of the <script> tag. It ensures that the script is run in lexical order with surrounding nodes

Superclass Chain

node (LzNode) » script (LzScript)

Known Subclasses

Details

Methods (1)

initialize()
<method name="initialize" args="parent, args" />
public function initialize(parent, args);

LZX Synopsis

<class name="LzScript" extends=" LzNode ">
  <method name=" initialize " args="parent, args" />
</class>

JavaScript Synopsis

public LzScript extends  LzNode  {
  prototype public function initialize (parent, args);
}