Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Minimal Object Pattern

View prim.js
1 2 3 4 5 6 7 8 9 10 11
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}
View prim.js
1 2 3 4 5
// singleton
 
var prim = require('prim')
 
console.assert(prim.method() == 'foo')
View prim.js
1 2 3 4 5 6 7
// OOP 'Class' (MooTools, Prototype.js, etc...)
 
var Prim = require('prim').constructor
 
var myPrim = new Prim
 
console.assert(myPrim.method() == 'foo')
View prim.js
1 2 3 4 5 6 7
// ES5
 
var prim = require('prim')
 
var myPrim = Object.create(prim)
 
console.assert(myPrim.method() == 'foo')
View prim.js
1 2 3 4 5
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
Something went wrong with that request. Please try again.