Created
March 29, 2013 19:06
-
-
Save matthewrobb/5272889 to your computer and use it in GitHub Desktop.
Simple mixin function with prototype support
This file contains 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
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