Created
June 6, 2015 15:57
-
-
Save jakoblind/462472879b4150760383 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list1 = [{a: 1}, {b: 2}, {c:3}]; | |
var list2 = _.map(list1, function(i){ | |
i = "test"; | |
return "test"; | |
}); | |
//list1 is not changed but a new list is created: | |
//JSON.stringify(list1): "[{"a":1},{"b":2},{"c":3}]" | |
//JSON.stringify(list2); "["test","test","test"]" | |
var list3 = _.map(list1, function(i){ | |
i.a = "hello"; | |
return "test"; | |
}); | |
//list1 is changed: | |
//JSON.stringify(list1) "[{"a":"hello"},{"b":2,"a":"hello"},{"c":3,"a":"hello"}]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment