Created
September 29, 2011 20:38
-
-
Save subtleGradient/1251865 to your computer and use it in GitHub Desktop.
Minimal Object 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
exports.constructor = function(){} | |
exports.constructor.prototype = exports | |
exports.create = function(){ | |
return this.constructor.apply(Object.create(this), arguments) | |
} | |
exports.property = 'foo' | |
exports.method = function(){return this.property} |
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
// singleton | |
var prim = require('prim') | |
console.assert(prim.method() == 'foo') |
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
// OOP 'Class' (MooTools, Prototype.js, etc...) | |
var Prim = require('prim').constructor | |
var myPrim = new Prim | |
console.assert(myPrim.method() == 'foo') |
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
// ES5 | |
var prim = require('prim') | |
var myPrim = Object.create(prim) | |
console.assert(myPrim.method() == 'foo') |
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
var prim = require('prim') | |
var myPrim = prim.create() | |
console.assert(myPrim.method() == 'foo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very clever.