Monday 14 December 2009

JavaScript - Naming Conventions and Coding Standards

Naming Conventions:

I am going to write naming conventions for JavaScript. This will be inspired by ASP.NET AJAX Library.

Target Convention Example

js file name

Pascal Casing

MicrosoftAjax.js

Namespace

Pascal Casing

Sys.Serialization;
Type.registerNameSpace(“Model”);

Class

Pascal Casing

JavaScriptSerializer

Methods

Camel Casing

serialize(text);
deserialize(object);

Input Parameters

Camel Casing

parse(text); // text is in camel case

Private Class Variables

use _ with camel casing

var _firstName;


Public Class Variables

this.<Camel Casing>

this.isStrong = true; // this is used to define a member as public

Class Properties

// properties are public

get_<camel casing>

or

set_<camel casing> 

this.get_firstName: function(){
return _firstName;
}

this.set_firstName: function(value){
this._firstName = value;
}
Method Variables Camel Casing var index = 0;
     

Coding Standards:

No comments: