Skip to content

Instantly share code, notes, and snippets.

@matthewrobb
Created March 29, 2013 19:06
Show Gist options
  • Save matthewrobb/5272889 to your computer and use it in GitHub Desktop.
Save matthewrobb/5272889 to your computer and use it in GitHub Desktop.
Simple mixin function with prototype support
function mixin(receiver, source) {
var descriptors = {};
for(var name in source) {
if(source.hasOwnProperty(name)) {
if(typeof receiver == "function" && name == "prototype") {
receiver.prototype = mixin(Object.create(receiver.prototype), source.prototype);
} else {
descriptors[name] = Object.getOwnPropertyDescriptor(source, name);
}
}
}
Object.defineProperties(receiver, descriptors);
return receiver;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment