xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Objec.assign bug All In One

Objec.assign bug All In One

shallow copy / 浅拷贝

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Deep_Clone

Error ❌

const log = console.log;

let status = {
  r: 0,
  x: 0,
  y: 0,
  w: 0,
  h: 0,
};

let obj = {
  x: 100,
};

let result = Object.assign({}, status, obj);
// let result = {...status, ...obj};

log(`bug `, result);


OK ✅

image

chrome browser bug

https://repl.it/@xgqfrms/object-assign-and-browser-bug

chrome bug ???

OK

Deep Clone

  1. JSON.parse(JSON.stringify(obj));

  2. lodash

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-01-06 10:55  xgqfrms  阅读(193)  评论(3编辑  收藏  举报