I am trying to create javascript extendable library with submodules in different files. I am using Module Pattern based on Ben Cherry article
module.js
var SERVICES = (function (service) {
var service = {},
privateVariable = 1;
function privateMethod() {
//
}
service.moduleMethod = function () {
//
};
return service;
}());
submodule.js
SERVICES.submodule = (function (service) {
var submodule = {},
privateVariable = 1;
submodule.moduleMethod = function () {
//
};
return submodule;
}(SERVICES));
What I want to achieve is the following. The module.js is a module which I want to act as a library. Submodules are separated in the different files, thus I am using Module Pattern. Clients will be able to write new submodules for the mentioned library (module.js). I want to create a script which will call library SERVICES with all submodules available. This script will be included in one front-end file just once, and there will be no need to change anything when someone writes new submodule. Library should load it.