Chapter 1. Naming Convensions
There's 6 basic rules.
- Every variable object name's 1st char should be a lower case.
Code: Select all
var myName = "Torisugari";
- Every constant object name should be upper cases.
Code: Select all
const MY_NAME = "Torisugari";
- Every constructor name's 1st char should be an upper case.
Code: Select all
function Mozillazine(){
this.description="A Cool Site";
this.name="mozillaZine";
this.url="http://www.mozillazine.org/";
}
var gMyFav = new Mozillazine(); - By prefix g the author means that is a global object, and unique in the window.
- By prefix a the author means that is an argument.
- By prefix _ the author means that is a private member.
Code: Select all
var bar=0; /*bar should be gBar*/
function foo(){
var gFoobar = 0; /* gFoobar is not a global value */
return gFoobar;
}
Code: Select all
function foo(bar){ /* bar should be aBar */
var aFoobar="foo" + bar; /* aFoobar is not an argument */
return aFoobar;
}
Code: Select all
var gFoo={
_bar:0
}
var foobar=gFoo._bar; /* _bar is a public member ? */
/* In other words, you can write only "this._bar" */
exceptions
A global function doesn't have to start with g.
My extensions are not good yet, so I'll correct them step by step.
Anybody, more rules, exceptions, comments?