Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Last active December 11, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/4589986 to your computer and use it in GitHub Desktop.
Save rwaldron/4589986 to your computer and use it in GitHub Desktop.
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