Skip to content

@subtleGradient /prim.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

Very clever.

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.