Reputation: 5133
I would like to know how can I create a module and manually create more instances of that module without impacting the global scope.
Right now I have something similar to this piece of code:
var myModule = (function(){
...
})();
myModule
is at this point in the global scope of my app.
What can I do to encapsulate this somewhere and call a new instance of it anytime I need one?
I am looking for something similar with Require.js or Angular.
Upvotes: 0
Views: 122
Reputation: 124
var myScope={};
(function(window) {
function Module(){
console.log('new instance of Module');
};
Module.prototype.someFunction = function(){
};
window.myScope.Module = Module;
}(window));
myModule = new myScope.Module();
Something like this?
Upvotes: 1