Skip to content

Instantly share code, notes, and snippets.

@jeffschwartz
Last active August 29, 2015 14:20
Show Gist options
  • Save jeffschwartz/dd3bcd88ca30ffb27742 to your computer and use it in GitHub Desktop.
Save jeffschwartz/dd3bcd88ca30ffb27742 to your computer and use it in GitHub Desktop.
Create a prototype
/**
* Creates a new object that can be used as a protype for a ctor.
* @param api object The object whose own properties are to be copied to
* the new prototype object.
* @param ctr function The constructor function which will be set as the
* value of the new prototype's contructor property.
* @returns an object that can be uses as a protytpe.
*/
function createPrototype(api, ctr){
var ownProps = Object.getOwnPropertyNames(api),
prototype = {};
ownProps.forEach(function(prop){
prototype[prop] = api[prop];
});
prototype.constructor = ctr;
return prototype;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment