Created
June 11, 2015 22:13
-
-
Save dgowrie/c24da624141bb77d5eff to your computer and use it in GitHub Desktop.
Revealing Module Pattern, with internal prototype / constructor pattern
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
| var myModule = ( function($, undefined) { | |
| var _person = function(firstName, lastName, age) { | |
| this.firstName = firstName; | |
| this.lastName = lastName; | |
| this.age = age; | |
| }; | |
| _person.prototype.fullName = function() { | |
| return this.firstName + ' ' + this.lastName; | |
| }; | |
| var myModule = { | |
| Person: _person, | |
| }; | |
| return myModule; | |
| })(jQuery); | |
| // usage of instances | |
| var newPerson = new myModule.Person('George', 'Costanza', 65); | |
| var newPerson2 = new myModule.Person('Jerry', 'Seinfeld', 67); | |
| newPerson.fullName(); // "George Costanza" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment