obj1 = Object.create({}, { property: { enumerable: true, value: 42 } })
> obj1.property = 56
> 56
> obj1.property
> 42
with use st
You can write your own function that also copies over property attributes:
function extend(target, ...sources) {
for (let source of sources)
for (let key of Object.keys(source))
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
return target;
}
But notice there is good reason why Object.assign
does not, it could have weird effects if getters and setters are closures.