Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created January 16, 2017 22:58
Show Gist options
  • Save C-Rodg/afa248c14470c5f47d13abe2e8806345 to your computer and use it in GitHub Desktop.
Save C-Rodg/afa248c14470c5f47d13abe2e8806345 to your computer and use it in GitHub Desktop.
A mixin for acquiring object properties without modifying the prototype chain.
function mixin(receiver, supplier) {
if(Object.getOwnPropertyDescriptor) {
Object.keys(supplier).forEach(function(prop) {
let descriptor = Object.getOwnPropertyDescriptor(supplier, prop);
Object.defineProperty(receiver, prop, descriptor);
});
} else { // For older browsers, does not support accessor properties
for(let prop in supplier) {
if (supplier.hasOwnProperty(prop) {
receiver[prop] = supplier[prop];
}
}
}
return receiver;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment