Recommended Code Standard for Developing JS Modules


Agreement on naming

0. Hilighting words - change of simbol register (camel case), Tabulation - 3 signs, not blank spaces.

1. Functions - constrcutors that work with an operator are named with a capital letter


function AbstractDriver () {
};

var Driver_1 = new AbstractDriver ();


2. Functions and public functions - object methods are named with a small letter


function updateRequest () {
};

function AbstractDriver () {

this.getData () {

};

};
var Driver_1 = new AbstractDriver ();

Driver_1.getData ();


3. Public but temporary or private functions object methods are named with a low line and a small letter


function AbstractDriver () {

this._getPassword () {
};

_prepare = function () {

}

_prepare (); // Приватный метод

};

var Driver_1 = new AbstractDriver ();

Driver_1._getPassword (); // Временный метод API


4. Names of properties are written with a small letter
var lastIndex = 0;


5. Constants - all letters are capital, words are devided withe a low line

var EVENT_GENERATED_END = 0;
6. Incoming function parameters have in_ prefix and are written with a small letter
function resizeProject (in_width, in_height) {

};
7. Outgoing function parameters have out_ prefix, and the first syllable is written with a small letter.
function checkConnection () {

return out_status;

};
8. Namespace - all signs are capital


KNX = {};
9. Placing blank spaces:
- after key words, before an opening bracket, before a comma


function name (in_arg1, in_arg_2) {

return out_arg;

};


10. Semi colon: at the end of a line, after a closing bracket
11. Documentation of methods, constructors


/**

 * Purpose of the function - назначение метода

 *

 * @namespace Name of the namespace - имя пространтсва

 * @method / @onstructor Name of the function - имя метода или конструктора

 * @param  {Type} Description - входящие данные

 * @return {Type} Description - выходные данные

 */
/**

 * Create the data base of the app

 *

 * HDL

 * @method createDataBase

 * @param  {String} Path of the file

 * @return {Boolean} Success of the action

 */

function createDataBase (in_path) {

return out_result;

};

This article was helpful for 2 people. Is this article helpful for you?