A framework for writing truly modular JavaScript
MIT License
ModJS is a javascript framework that utilizes the Module, Factory, and Mediator patterns to be a base for projects that allows for the quick integration of complex, scalable, and application level javascript without starting from scratch. There are four tiers to the framework which allows for better seperation of code and a more scalable architecture. The four levels are:
Every method in the framework is documented and available with examples and whether or not the function should be used publicly. For documentation simple navigate to "path/to/project/docs/" in your browser and the full documentation will be available to you. ( Documentation created using YUIdoc )
To see the framework in action simply download the project and navigate to "path/to/project/" in your browser. The example searches Instagram for the specified hashtag and displays recent images with that tag
By decoupling all the layers of the application you can drop in your modules from previous projects and with minor updates you will already have large chunks of functionality at your disposal. You could also change out the jQuery base layer with your tool of choice and with only editing about 15 functions still be able to use all of your previous modules because the sandbox layer never has to change. It makes projects infinitely scalable by 1) seperating business logic into neat little packages, greatly decreasing the potential for unforseen issues caused by altering code ( we have all experienced the domino effect, you make one change and suddenly ten other functions need to be updated ), and 2) seperating the core of the application from a third-party library making the framework super-adaptable to any project.
If you would like to contribute to this project:
Once the changes are reviewed they will either be added or the merge request will be closed.
This should include any parameters passed in, what the function does, and what it returns. Here is an example of a commented utility function:
/**
* @description check to see if object is an array
* @param {unknown} arr
* @return {Boolean} true or false
* @method is_array
* @private
*/
MOD.core.util.is_array = function( arr ) {
return ( typeof arr === 'object' && ( Object.toString.call( arr ) === '[object Array]' ) ) ? true : false;
};
NOT OKAY:
var employee = new Person({
name: 'John Doe',
age: 27,
occupation: 'Developer'
})
greetEmployee( employee.name )
OKAY:
var employee = new Person({
name: 'John Doe',
age: 27,
occupation: 'Developer'
});
greetEmployee( employee.name );
Notice the semi-colons at the end of each statement
ALSO OKAY:
var employee = new Person({
name: 'John Doe',
age: 27,
occupation: 'Developer'
}),
greetEmployee;
greetEmployee = function( name ) {
alert( 'Hello, ' + name + '! Glad to have you on board!' );
};
greetEmployee( employee.name );
Function parameters should be spaced at the beginning and end, and after commas. Example:
function useSpaces( param1, param2 ) {
window.console.log( 'I use spaces in my paramters for visual cleanliness.' );
}
useSpaces( param1, param2 );
When writing functions it is important to group similar items and to use proper indentation. Every inner operation should indent one more tab set than its parent element. Variables should be grouped together and different operations should have a line of space around them. Example:
var options = select.options,
i = 0,
len = options.length;
for ( ; i < len; ) {
//add a class to each item
if ( options[ i ].selected === true ) {
return options[ i ].value;
}
// increment our counter
++i;
}