Skip to content

Instantly share code, notes, and snippets.

View austinhaas's full-sized avatar

Austin Haas austinhaas

View GitHub Profile
@puffnfresh
puffnfresh / getinstance.js
Created March 29, 2013 02:04
Two nice helper functions for creating constructors in JavaScript.
// Polyfill for Object.create
function create(proto) {
function Ctor() {}
Ctor.prototype = proto;
return new Ctor();
}
// Always returns an instance of constructor
function getInstance(self, constructor) {
return self instanceof constructor ? self : create(constructor.prototype);