Return to Snippet

Revision: 3706
at September 4, 2007 03:27 by 1man


Initial Code
function mooTutorial() {
	var city = { //create the city object
		numberOfCars : 0, //define number of cars property
		hasTraffic: true, //define if it has traffic
		grow: function(howMany) { //creates a grow() method. looks for variable howMany.
			this.numberOfCars += howMany; //adds howMany to numberOfCars.
		}
	}//This is where the object gets parsed, order of members is unimportant.
	console.info(city.numberOfCars); //outputs 0
	city.grow(10);
	console.info(city.numberOfCars); //outputs 10
}
window.onload = mooTutorial();

Initial URL

                                

Initial Description
Create a simple object and add properties and a method. Note where the object is parsed (not from top to bottom).

Initial Title
Basic Object Creation

Initial Tags
javascript, object

Initial Language
JavaScript