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;
	}

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:


	var card = new Card (CLUBS, 9);

The variable then holds a reference to the object, somewhere in memory.

(Yes, I still use var rather than let. It is more flexible and I have no problem with it. I would not use it for global variables though: I prefer to have just one global const to hold anything I need to be global, such as GAME. If you would rather use let wherever I use var, that's fine.)

Next page | Contents page |