Created
March 31, 2014 07:42
-
-
Save baniol/9887173 to your computer and use it in GitHub Desktop.
javascript, design patterns, type pattern
This file contains 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
// 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