Created
December 10, 2015 17:56
-
-
Save jacwright/4c4b0444ced999667403 to your computer and use it in GitHub Desktop.
Constructor that returns a new constructor
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
function Model() { | |
var constructor = function(props) { | |
Object.keys(props).forEach(function(key) { | |
this[key] = props[key]; | |
}, this); | |
}; | |
constructor.prototype = Object.create(Model.prototype); | |
constructor.prototype.constructor = constructor; | |
return constructor; | |
} | |
Model.prototype.foo = function() {}; | |
var Name = new Model(); | |
n = new Name({ first: 'Bob', last: 'Jones' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment