You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mhagmajer
changed the title
Implement a resource which adds a property to an object
Implement extend resource create a new object with added property
Jul 10, 2020
let a = { firstName: 'John' } // object X
a = extend(a, { firstName: 'Bill' } // object Y
Object X is going to stay the same no matter what you do. Object Y will be creating by extending object X which will overwrite its only property. Variable a is like a pointer. It can change what it points to because it is declared with let. It initially points to object X and then it points to object Y. Object X and object Y are immutable.
Yes, I know. That's why I wrote 'change' in italics. Anyways, you answered my question: yes, extend will also work on a key that is already defined. So using extend could be a workaround for updating a value in a map.
Anyway, don't we need a set resource for maps?
While we have a resource for setting a value in an array (
set
resource), I think we don't have such for objects.It is up to discussion whether a new resource should be created or rather
set
should be extended to work for objects.The text was updated successfully, but these errors were encountered: