Skip to content

Instantly share code, notes, and snippets.

@js1972
Last active August 29, 2015 13:57
Show Gist options
  • Save js1972/9383609 to your computer and use it in GitHub Desktop.
Save js1972/9383609 to your computer and use it in GitHub Desktop.
JavaScript Constructor Module Pattern. This module returns a constructor function which can be called with new. This is the alternative to the standard module pattern which returns an object. #javascript
myapp.module = (function () {
// private variables and functions
var foo = "bar",
Constuctor;
// constructor
Constructor = function () {
};
// prototype
Constructor.prototype = {
constructor: Constructor,
something: function () {
}
};
// return module
return Constructor;
})();
var my_module = new myapp.module();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment