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>
Copyright © 2002-2007 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.