I want to write a JS library and process it like this:
var c1 = Module.Class(); c1.init(); var c1 = Module.Class(); c2.init();
And, of course, c1 and c2 cannot use the same variables. I think I know how to do this with objects, this would be:
var Module = { Class = { init = function(){ ... } } }
But the problem is that I cannot have multiple instances of the class if I write this way. Therefore, I am trying to achieve the same thing as a function, but I do not think that I am doing it right.
(function() { var Module; window.Module = Module = {}; function Class( i ) {
I have no clue if this is possible, but I accept suggestions for another way to create this module. I don't know if this matters either, but I use jQuery inside this library.
javascript object module-pattern
Luiz Fernando
source share