Specifications

with the object they are assigned to, so even though the object (obj in the above example) gets
the property myProperty, it does not mean that other objects of type Object will have the property
"myProperty", unless explicitly stated.
Comments
JavaScript supports the same commenting syntax as C++. One-line comments may appear on a
line of their own or after the statements on a line. Multi-line comments may appear anywhere.
// A one-line comment.
/*
A multi-line
comment.
*/
Built-in types and objects
(The contents of this topic is adapted from documentation provided by Trolltech.)
JavaScript provides a variety of built-in types (or classes) and objects.
The built-in types include Array, Boolean, Date, Function, Number, Object, Point, Rect, RegExp,
Size and String.
The only built-in object is Math.
Array
An Array is a datatype which contains a named list of items. The items can be any JavaScript
object. Multi-dimensional arrays are achieved by setting array items to be arrays themselves.
Arrays can be extended dynamically simply by creating items at non-existent index positions.
Items can also be added using push(), unshift() and splice(). Arrays can be concatenated together
using concat(). Items can be extracted using pop(), shift() and slice(). Items can be deleted using
splice(). Arrays can be turned into strings using join() or toString(). Use reverse() to reverse the
items in an array, and sort() to sort the items. The sort() function can be passed a comparison
function for customized sort orders.
In general, operations that copy array items perform a deep copy on items that are Number or
String objects and a shallow copy on other objects.
Array Construction
Arrays can be constructed from array literals or using the new operator:
var mammals = [ "human", "dolphin", "elephant", "monkey" ];
var plants = new Array( "flower", "tree", "shrub" );
var things = [];
for ( i = 0; i < mammals.length; i++ ) {
things[i] = new Array( 2 );
things[i][0] = mammals[i];
things[i][1] = plants[i];
}
Arrays can be initialized with a size, but with all items undefined:
var a = new Array( 10 ); // 10 items
Array Access
Array items are accessed via their names. Names can be either integers or strings.
371
Enfocus Switch 10