Skip to content

Repository files navigation

assignProperties

Build StatusCoverage StatusWebReflection status

An Object.assign like utility that preserve descriptors, as in accessors or value, or configurable, or writable, etc.

importassignPropertiesfrom'assign-properties';constassignProperties=require('assign-properties');// <script src="https://unpkg.com/assign-properties">

Same Object.assign API

// the issue with assign is that copies are valuesconstbefore=Object.assign({},{getrandom(){returnMath.random()}});// mixins are broken this waybefore.random===before.random;// true// with assignProperties, everything is fineconstafter=assignProperties({},{getrandom(){returnMath.random()}});// the getter is passed along instead of being lost in the processafter.random===after.random;// false

Object spread suffers the same issue

constbase={getrandom(){returnMath.random()}};constspread={...base};spread.random===spread.random;// true

So, if you want to bring accessors to the mix, this module is your stop.

About

An `Object.assign` like utility that preserve descriptors

Resources

Stars

16 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages