Next page | Contents page |

Naming conventions

Although JavaScript does not enforce, or even recommend, naming conventions it is really useful to have some, and get into the habit of using them. When reading a section of program it can make it so much clearer, showing the kinds of things we are dealing with.

I recommend the following.

To further explain the use of object types we will see examples like this in the following pages:

We define the type Card with a function that sets property values:


	function Card (suit, value)
	{
	  this.suit = suit;
	  this.value = value;
	}

Note the keyword this which means the current object, the new one being constructed by this function.

Functions like this which define object types have names beginning upper case. All other plain functions or methods will be named like variables, starting small.

Then objects of type Card are constructed with the new operator and can be assigned to a variable like this:


	let card = new Card (CLUBS, 9);

The variable then holds a reference to the object, wherever the browser has put it in memory.

Next page | Contents page |