Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy the specified enumerable properties (strings or symbols) from the source object to the destination object
function assignProps(source, dest, props) {
const descriptors = {};
props.forEach(name => {
let desc = Object.getOwnPropertyDescriptor(source, name);
if (desc && desc.enumerable) {
descriptors[name] = desc;
}
});
Object.defineProperties(dest, descriptors);
}
const a = Symbol('a');
const one = {[a]: 'alpha', b: 'beta', z: 'omega'};
Object.defineProperty(one, 'c', { value: 'C', enumerable: false })
const two = {b: 2, c: 3};
assignProps(one, two, [a, 'b', 'c'])
console.log(two)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.