VOOZH about

URL: https://qiita.com/sasaplus1/items/380d1fe6d5400c1beedf

⇱ _.extendはcloneをしてくれるはず、と勘違いしていた話 #Underscore.js - Qiita


👁 Image
2

Go to list of users who liked

2

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@sasaplus1(Takafumi Sasage)

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

2
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

Go to list of users who liked

2
0

Go to list of comments

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

Go to list of users who liked

2