Skip to content

Instantly share code, notes, and snippets.

@tlivings
Last active December 18, 2015 07:09
Show Gist options
  • Select an option

  • Save tlivings/5744253 to your computer and use it in GitHub Desktop.

Select an option

Save tlivings/5744253 to your computer and use it in GitHub Desktop.
Javascript extend utility function.
/**
* Extend an Object from another Object.
* @param child
* @param parent
* @param proto - prototype mixins
* @returns {*}
*/
function(child, parent, proto) {
//Constructor
var properties = {
constructor: {
value: child
}
};
//Mixin prototype properties
if(proto) {
Object.keys(proto).forEach(function(key) {
properties[key] = {
value : proto[key]
}
});
}
//Extend
child.prototype = Object.create(parent.prototype, properties);
//Convenience object
child.super_ = parent;
return child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment