assignProperties
An Object.assign like utility that preserve descriptors, as in accessors or value, or configurable, or writable, etc.
import assignProperties from 'assign-properties'; const assignProperties = require('assign-properties'); // <script src="https://unpkg.com/assign-properties">
Same Object.assign API
// the issue with assign is that copies are values const before = Object.assign({}, {get random() { return Math.random() }}); // mixins are broken this way before.random === before.random; // true // with assignProperties, everything is fine const after = assignProperties({}, {get random() { return Math.random() }}); // the getter is passed along instead of being lost in the process after.random === after.random; // false
Object spread suffers the same issue
const base = {get random() { return Math.random() }}; const spread = {...base}; spread.random === spread.random; // true
So, if you want to bring accessors to the mix, this module is your stop.