Looking to develop a JavaScript library and manage it in the following manner:
var c1 = Module.Class();
c1.init();
var c2 = Module.Class();
c2.init();
It's crucial that c1 and c2 do not share the same variables. My initial thought is to use objects:
var Module = {
Class: {
init: function(){
...
}
}
}
However, this structure doesn't allow for multiple instances of Class. I've been attempting to achieve the same using functions, but encountering issues:
(function() {
var Module;
window.Module = Module = {};
function Class( i ) {
//How can "this" refer to Class instead of Module?
this.initial = i;
}
Class.prototype.execute = function() {
...
}
//Public
Module.Class = Class;
})();
Unsure if this approach is feasible and open to alternate suggestions on creating this module. Not sure if it's pertinent, but I am incorporating jQuery within this library.