Created
April 8, 2014 08:08
-
-
Save atmd83/10101003 to your computer and use it in GitHub Desktop.
require.js module style guide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Mini style guide for require.js modules | |
* Dependencies should each have a new line, indented from the array literal (square brackets) | |
* having them on each line means its easy to see the number of dependencies you have. | |
* The function names (exposed by your dependencies) should also be declared on a new line, | |
* this makes it really easy to add new modules at a later time and its quick to check against | |
* your dependencies list. | |
* They should also be prefixed (i.e. $someModule) so that they are very easily identified as modules | |
* when used in your code. (Dependent on module size, this might not be required in smaller modules) | |
*/ | |
require( | |
[ | |
'someModule', | |
'anotherModule', | |
'finalModule', | |
'moduleAddedLater' | |
], | |
function( | |
$someModule, | |
$anotherModule, | |
$finalModule, | |
$moduleAddedLater | |
){ | |
/* | |
* Private variables and functions at the top | |
* these provide internal functionality not exposed to the module. | |
* function names should be prefixed for readability (ie. _func) | |
* N.B. jslint by default doesnt like dangling underscores. | |
*/ | |
var _someVariable = 'some important but provate value'; | |
function _myPrivateFunction() { | |
//some code | |
} | |
function _myOtherPrivateFunction() { | |
// some code | |
} | |
var self = {}; | |
/* | |
* Public methods of the 'self' object go here | |
* They are returned by the module and exposed for use. | |
*/ | |
self.prototype.myPublicMethod = function() { | |
// some code | |
} | |
self.prototype.myOtherPublicMethod = function() { | |
// some code | |
} | |
return self; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment