{{Needs Work}}
Alfresco Development Standards for Client-side Javascript. Internal Use.
Development standards for other languages are here.
/* This is the recommended comment format outside a function block. */
Multi-line comments should be aligned with existing indentation and each line should start with an asterisk.
/**
* This is a multi-line comment.
* Note the alignment of the asterisks.
*/
/* Should use this commenting style because this is not within a function. */
function foo()
{
// Valid comment format within a function block.
}
function myFunction(one, two)
{
...
}
var MyObj =
{
myFunction: function MyObj_myFunction(one, two)
{
...
}
}
MyObj.myFunction(123, 456);
/**
* Adds three numbers together and returns sum.
* <pre>
* addNumbers(1, 2, 3);
* </pre>
* @method addNumbers
* @param one {int} the first number to be added
* @param two {int} the second number in the addition
* @param three {int} the third number used in the sum
* @return {int} the sum of parameters one, two and three
*/
addNumbers: function Util_addNumbers(one, two, three)
{
return (one + two + three);
}
myCallback =
{
fn: function MyCallback(obj)
{
...
},
obj: myArbitraryObject,
scope: this
}
callbackFunction1 = null,
callbackFunction2 =
{
fn: function(obj){},
obj: null,
scope: this
}
...
if (callbackFunction1 && (typeof callbackFunction1.fn == 'function')
{
callbackFunction1.fn.call(callbackFunction1.scope ? callbackFunction1.scope : this, callbackFunction1.obj);
}
callbackFunction2.fn.call(callbackFunction2.scope, callbackFunction2.obj);
doBeforeSubmission =
{
fn: function(dataObj, obj)
{
return dataObj;
},
obj: null,
scope: this
}
...
var dataObj = { ... some data ... };
dataObj = doBeforeSubmission.fn.call(doBeforeSubmission.scope, dataObj, doBeforeSubmission.obj);
var total = addNumbers(1, 2, 3);
if (condition)
{
...
}
if (some condition)
{
...
}
else
{
...
}
if (condition) return; /* DO NOT USE */
if (condition) /* OK */
{
return;
}
return /* DO NOT USE */
{
param1: 'foo',
param2: 'bar'
}
return { /* BETTER */
param1: 'foo',
param2: 'bar'
}
return ( /* PREFERRED */
{
param1: 'foo',
param2: 'bar'
});
if (x === null)
{
...
}
if (y !== null)
{
...
}
if (a = b) /* INTENTIONAL ASSIGNMENT, OR BUG? */
if (Service.isAvailable)