Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Created July 14, 2014 14:05
Show Gist options
  • Save heymichaelp/75f864259a7320fc67d1 to your computer and use it in GitHub Desktop.
Save heymichaelp/75f864259a7320fc67d1 to your computer and use it in GitHub Desktop.
function extend(protoProps, staticProps) {
var parent = this;
var child;
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
_.extend(child, parent, staticProps);
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
if (protoProps) _.extend(child.prototype, protoProps);
child.__super__ = parent.prototype;
return child;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment