JavaScript API Reference/Creating Custom Java Script Objects

Simple Objects with Properties

In the simple case, you may create an object that only contains data variables, and no functions. Data variables that belong to an object are called properties .

Simple objects can be created using standard JavaScript object literal syntax :

/*
* Object that defines a marker displayed on the map.
*/
var mapMarker = {
// summary text line, displayed as a tooltip
summary: '',

// HTML content, displayed when user clicks on the marker
content: '',

// X and Y coordinates of the marker on the map
coordinates: ''
};


Note that commas separate properties, but the last property does not have a trailing comma.

You can examine or change this object’s properties in the code:

if (mapMarker.summary == '') {
mapMarker.summary = 'No summary provided';
}


You can also pass the object to a function:

function displayMarker(map, marker) {
var coordinates = marker.coordinates;
... the code that draws the marker goes here ...
}