-
-
Notifications
You must be signed in to change notification settings - Fork 3
Coding Guidelines
Wesley De Groot edited this page Oct 23, 2015
·
3 revisions
_ _____
| | / ____|
| | | (___
_ | | \___ \
______ _ | |__| | ____) |
|______| (_) \____/ |______/
Hi,
First of all. thanks for looking to the guidelines.
The Guidelines are simple.
Function naming, and documentation.
Please use a name what everyone will understand. Examples: Good:
- myFunctionName
- changeHTML
- isEmpty
- isUndefined
Bad:
MyFunctionNamemyfunctionnameMYFunctionNamemYFunctionName
Documentatie your module.
We'll use a PHP-Doc style for comments, that is the most readable for everyone.
/**
* myFunctionName
*
* function description
*
* @param object object
* @param myParam this is my parameter
* @see https://github.com/wesdegroot/_.js/wiki/module_myModule
* @example _().myFunctionName('hi');
*/
After a if/function we'll start opening on the next line
if ( something = true ) // Yes those spaces between are necessary.
{
// action
}
And
function ( myParam ) // Yes those spaces between are necessary.
{
// action
}
Variable declaration is good but please make it readable
Example how we Don't do it:
var myVar;
var myVar1;
var myVar2='default';
var myVar3;
var myVar4 = 'ok';`
We Don't do it that, way we prefer:
var myVar,
myVar1,
myVar2 = 'default',
myVar3,
myVar4 = 'ok'; // the last one must end with a ;
- Todo
First we start with a check if the _.js is loaded correctly.
if(!window._)
{
alert('some custom alert that _.js is missing');
}
else
{
// Here goes my plugin
}
We'll extend the system by using _.fn.myModuleName
= function (my parameters
)
Example:
if(!window._)
{
alert('some custom alert that _.js is missing');
}
else
{
_.fn.myModuleName = function ( MyParameter )
{
// MyModuleCode
}; // yes, for compressing we'll end each line with a semicolon (;)
}
And if we're manipulating HTML then we'll do this
if(!window._)
{
alert('some custom alert that _.js is missing');
}
else
{
_.fn.myModuleName = function ( MyParameter )
{
var len = this.length;
while (len--)
{
this[len].innerHTML = 'MyModuleCode is running smoothly!';
}
};
}
© Wesley de Groot • CC-BY 4.0 • WDGWV