Directory structure
Javascript should follow the following directory structure on a project
- js
- lib Add javascript libraries such as jquery here
- modules Add bright custom js modules here
Syntax
- Use single quotes for strings
- Use camelCase for variables and function names
- Opening curly bracket on same line
- Indentation is 4 spaces (no tabs)
var foo = 'lets use single quotes';
function myReturnFunction(argument) {
return argument;
}Revealing module pattern
All code should be written using the revealing module pattern
var myJsModule;
myJsModule = (function() {
'use strict';
function init(){
}
return {
init:init
};
}());You will need to initialise the module in your templates or another js file.
myJsModule.init();
Comments
Use // for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment.
The following Gists provide sublime text snippets for top-level (tab trigger = cb) and second level (tab trigger = cb2) multi-line comments.