Skip to content

An `Object.assign` like utility that preserve descriptors

Notifications You must be signed in to change notification settings

WebReflection/assign-properties

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

assignProperties

Build Status Coverage Status WebReflection status

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.

About

An `Object.assign` like utility that preserve descriptors

Resources

Stars

Watchers

Forks

Packages

No packages published