This syntax is similar to Java, although ECMAScript requires parentheses to be used only if there are one
or more parameters. If there are no parameters, such as in the previous line of code, then the parentheses
can be safely omitted:
var o = new Object;
Chapter 3, “Object Basics,” contains a more in-depth look at objects and their behaviors. This section
focuses on those reference types that have primitive equivalents.
The Object class
class itself isn’t very useful, but you should understand it before moving on to the other
classes. Why is that? Because the
class in ECMAScript is similar to
It is the base class from which all ECMAScript classes inherit. All the properties and methods of the
Object class are also present in the other classes, and so to understand the
class is to understand
all the others better.
class has the following properties:
— A reference value (pointer) to the function that created the object. For the
class, this points to the native
— A reference value to the object prototype for this object. Prototypes are discussed
further in Chapter 3. For the all classes, this returns an instance of
class also has several methods:
— Determines if a given property exists for the object. The
property must be specified as a string (for example,
— Determines if the object is a prototype of another object.
— Determines if a given property can be enumerated by
statement (discussed later in this chapter).
— Returns a primitive string representation of the object. For the
this value is undefined in ECMA-262 and, as such, differs in each implementation.
— Returns the most appropriate primitive value of this object. For many classes,
this returns the same value as
Each of the properties and methods listed previously are designed to be overridden by other classes.
Although the parentheses aren’t required, it’s always best to include them in order
to avoid confusion.
05_579088 ch02.qxd 3/28/05 11:35 AM Page 26