My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Tuesday, October 06, 2015

Object.assign Side Effects and How To Copy

In How To Copy Objects post I'll explain the difference between various native ways to copy own keys and properties, describing also the fact that Object.assign is full of surprises and side effects.

As example, assigning to an object something like {get next() {return ++this.i}, i:0} instead of {i:0, get next() {return ++this.i}} will result in different values copied over: next === 1 and i === 1 in the first case, next === 1 and i === 0 in the second one.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.