Operators > {} (object initializer)

{} (object initializer)

Syntax

object {name1: value1,
	name1: value2,
...
	nameN: valueN };

Arguments

object The object to create.

name1,2,...N The name of the property.

value1,2,...N The corresponding value for each name property.

Description

Operator; creates a new object and initializes it with the specified name and value property pairs. The created object has the generic Object object as its prototype. Using this operator is the same as calling new Object and populating the property pairs using the assignment operator. Using this operator is an alternative to using the new operator, which allows for the quick and convenient creation of objects.

Player

Flash 5 or later.

Example

The following code shows how an empty object can be created using the object initializer operator and using the new Object:

object = {};
object = new Object();

The following creates an object account initializing the properties name, address, city, state, zip, and balance:

account = { name: "John Smith",
	address: "123 Main Street",
	city: "Blossomville",
	state: "California",
	zip: "12345",
	balance: "1000" };

The following example shows how array and object initializers can be nested within each other:

person = { name: "Peter Piper",
	children: [ "Jack", "Jill", "Moe",] };

The following example is another way of using the information in the previous example above, with the same results:

person = new Person();
person.name = 'John Smith';
person.children = new Array();
person.children[0] = 'Jack';
person.children[1] = 'Jill';
person.children[2] = 'Moe';

See also

[] (array access operator)
new 
Object (object)