Create a gist now

Instantly share code, notes, and snippets.

Embed
Minimal Object Pattern
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}
// singleton
var prim = require('prim')
console.assert(prim.method() == 'foo')
// OOP 'Class' (MooTools, Prototype.js, etc...)
var Prim = require('prim').constructor
var myPrim = new Prim
console.assert(myPrim.method() == 'foo')
// ES5
var prim = require('prim')
var myPrim = Object.create(prim)
console.assert(myPrim.method() == 'foo')
var prim = require('prim')
var myPrim = prim.create()
console.assert(myPrim.method() == 'foo')
@kitcambridge

This comment has been minimized.

Show comment
Hide comment
@kitcambridge

kitcambridge Feb 6, 2012

Very clever.

Very clever.

@subtleGradient

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment