Last active
December 11, 2015 10:58
-
-
Save rwaldron/4589986 to your computer and use it in GitHub Desktop.
Object.mixin impl from https://mail.mozilla.org/pipermail/es-discuss/2012-December/027039.html
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
Object.mixin = function( receiver, supplier ) { | |
return Object.getOwnPropertyNames( supplier ).reduce(function( receiver, property ) { | |
return Object.defineProperty( | |
receiver, property, Object.getOwnPropertyDescriptor( supplier, property ) | |
); | |
}, receiver ); | |
}; | |
var a = {}, name = "Rick"; | |
var b = Object.mixin(a, { | |
get name() { | |
return name; | |
} | |
}); | |
console.log( a.name ); // "Rick" | |
console.log( b.name ); // "Rick" | |
console.log( a === b ); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment