Object

Extends Literal. Whilst each type of theme template has access to existing objects, you can create your own basic objects within your template. An object can be initialised as a list of zero or more key value pairs, enclosed in curly braces {...}.

Instantiation

...
// initiate an empty object
var myEmptyObj = {};

var isCustomer = true;

// initiate an object with properties
var person = {
    name: 'Bobby Bobson',
    age: 21,
    customer: isCustomer // assign value of existing variable
};
...

Note that in initialisation is always followed by a semicolon.


Accessing properties

Having created an object, you'll need to read or change its properties. Object properties can be accessed by using the dot notation or the bracket notation.

...
// getting values
person.name; // Bobby Bobson
person['age']; // 21

// setting values
person.age = 22;
person['name'] = 'Bob Bobson';
...

Properties
length Number

The number of properties of the Object.



Methods
delete(String:property) Boolean

Returns true if the Object property was deleted or false if not.

get(String:property) Mixed

Returns the property of the Object if it exists or undefined if not.

hasProperty(String:property) Boolean

Returns true if the Object property exists or false if not.

keys() Array
Returns an Array containing the object's own enumerable property names.
set(String:property, Mixed:value) Object

Sets the property of the obejct with the value supplied and returns the original Object allowing chaining.

toJson() String

Returns a String containing a Json representation of the Object.