Skip to content

Instantly share code, notes, and snippets.

@dgowrie
Created June 11, 2015 22:13
Show Gist options
  • Select an option

  • Save dgowrie/c24da624141bb77d5eff to your computer and use it in GitHub Desktop.

Select an option

Save dgowrie/c24da624141bb77d5eff to your computer and use it in GitHub Desktop.
Revealing Module Pattern, with internal prototype / constructor pattern
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