Reputation: 8722
If I do this in Javascript (ES6):
let originalState = [
{ id : 1, name : "One"},
{ id : 2, name : "Two"},
{ id : 3, name : "Three"}
]
let newState = Object.assign({}, ...originalState)
Will the objects in "newState" reference the objects from "orignalState" in memory, or will they be cloned, taking up new memory?
Upvotes: 0
Views: 1067
Reputation: 665020
Will the objects in "newState" reference the objects from "orignalState" in memory, or will they be cloned, taking up new memory?
There won't be multiple new objects. There is only one object that is stored in the newState
variable, it's the one you've created with the object literal:
let newState = Object.assign({}, ...originalState)
// ^^ here
The properties in newState
will be created by standard assignment - they will exist separately from the ones of the originalState
objects but contain the same value.
Upvotes: 2