Skip to content

Instantly share code, notes, and snippets.

@baniol
Created March 31, 2014 07:42
Show Gist options
  • Save baniol/9887173 to your computer and use it in GitHub Desktop.
Save baniol/9887173 to your computer and use it in GitHub Desktop.
javascript, design patterns, type pattern
// Type Pattern
<package>.T = (function () {
var T = {};
// Shared properties and methods go here
T.create = function (…) {
vart = Object.create(this);
// Assign the own properties here
return t;
}
return T;
}());
// Instantiate with: varx = <package>.T.create(…);
// The "type" object and the prototype are one!
// Differs from operator new, which equates the type with the constructor (prototype separate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment