Last active
August 29, 2015 13:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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