Skip to content

Instantly share code, notes, and snippets.

@jacwright
Created December 10, 2015 17:56
Show Gist options
  • Save jacwright/4c4b0444ced999667403 to your computer and use it in GitHub Desktop.
Save jacwright/4c4b0444ced999667403 to your computer and use it in GitHub Desktop.
Constructor that returns a new constructor
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