Created
September 13, 2012 09:25
-
-
Save ericelliott/3713167 to your computer and use it in GitHub Desktop.
new Breaks Factory Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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