Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created September 13, 2012 09:25
Show Gist options
  • Save ericelliott/3713167 to your computer and use it in GitHub Desktop.
Save ericelliott/3713167 to your computer and use it in GitHub Desktop.
new Breaks Factory Objects
// Create a factory object that can be used to swap out the prototype used
// to instantiate new instances.
var factory = {};
factory.proto = {foo: 'bar'};
factory.create = function () { return Object.create(this.proto); };
var t1 = factory.create();
t1.foo; // "bar"
var t2 = new factory.create();
// TypeError: Object prototype may only be an Object or null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment