Created
January 16, 2017 22:58
-
-
Save C-Rodg/afa248c14470c5f47d13abe2e8806345 to your computer and use it in GitHub Desktop.
A mixin for acquiring object properties without modifying the prototype chain.
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, 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