Clone a new object simply by assigning the object to a variable using Immutable.js

I look at the documentation for Immutable.js, in particular the following:

var map1 = Immutable.Map({a:1, b:2, c:3}); var clone = map1; 

but I am confused by how simply assigning map1 to clone creates a clone, not a link?

Update: The docs document states "If an object is immutable, you can" copy "it by simply making a link to it instead of copying the entire object. Since the link is much smaller than the object itself, this will save memory and potentially increase execution speed for programs, which rely on copies (e.g. undo-stack).

I just tested this in jsbin, but the clone does === map1. I think that their use of the word "clone" in the documents is a little misleading.

+5
source share
1 answer

Since Immutable.Map is immutable, the concept of cloning is deprecated. Their thing is that you do not need to worry about cloning or not, it does not matter.

The documents are really confusing, and indeed, this link is not a clone. The effect of cloning will be the same anyway.

+2
source

Source: https://habr.com/ru/post/1238033/


All Articles