N-R > new

new

Syntax

new constructor();

Arguments

constructor A function followed by any optional arguments in the parentheses. The function is usually the name of the type of object (For example, Array, Math, Number, Object) to be constructed.

Description

Operator; creates a new, initially anonymous object, calls the function identified by the constructor argument, passes any optional arguments in the parentheses, and passes the newly created object as a value of the keyword this. The constructor function can then use this to instantiate the new object.

The _prototype_ property of the constructor function's object is copied into the _proto_ property of the new object. As a result, the new object supports all of the methods and properties specified in the constructor function's Prototype object.

Player

Flash 5 or later.

Example

The following example creates the objects book1 and book2 using the new operator.

function Book(name, price)
{
	this.name = name;
	this.price = price;
}
book1 = new Book("Confederacy of Dunces", 19.95);
book2 = new Book("The Floating Opera", 10.95);

See also

[] (array access operator)
{} (object initializer)

The constructor method section within an object entry.