Last active
August 29, 2015 14:20
-
-
Save jeffschwartz/dd3bcd88ca30ffb27742 to your computer and use it in GitHub Desktop.
Create a prototype
This file contains hidden or 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
/** | |
* 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