contents   index   previous   next



Variables and functions may be grouped together in one variable and referenced as a group. A compound variable of this sort is called an object in which each individual item of the object is called a property. In general, it is adequate to think of object properties, which are variables or constants, and of object methods, which are functions.


To refer to a property of an object, use both the name of the object and of the property, separated by the object operator ".", a period. Any valid variable name may be used as a property name. For example, the code fragment below assigns values to the width and height properties of a rectangle object and calculates the area of a rectangle and displays the result:


var Rectangle;


Rectangle.height = 4;

Rectangle.width = 6;


Screen.write(Rectangle.height * Rectangle.width);


The main advantage of objects occurs with data that naturally occurs in groups. An object forms a template that can be used to work with data groups in a consistent way. Instead of having a single object called Rectangle, you can have a number of Rectangle objects, each with their own values for width and height.


Terminology for objects

Predefining objects with constructor functions

Initializers for objects and arrays

Methods - assigning functions to objects

Object prototypes