2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

_.extendはcloneをしてくれるはず、と勘違いしていた話

Posted at

本当にただの勘違い、というか思い込みなのだけど……

var a = {a: 1},
    b;

b = _.extend(a, {b: 2});

console.dir(a);  // {a: 1, b: 2}
console.dir(b);  // {a: 1, b: 2}

b.a = 3;

console.dir(a);  // {a:3, b:2}
console.dir(b);  // {a:3, b:2}

oh...

_.extendしたらてっきりディープコピーされるのだと思ってたよ……

_.extendに渡すときに_.clone_.cloneDeepしないとだったんだね……

ちゃんとドキュメント読まないとだし、思い込んでないで試さないとだなあ。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?