What I am looking for is to be able to add to an object, but not to do something like messageStrings.x = 1 for each one.
For example, in one file we may have something like:
var messageStrings = {
Edit: "Edit",
Cancel: "Cancel"
}
and another file, want to add more to the object:
var messageStrings = {
Update: "Update",
Save: "Save"
}
What is the best way of doing a bulk add to an existing object?
Thanks.
Many libraries provide an “extend” function, which lets you do something like this:
which would give you an object with properties “default”, “more”, and “even.”
What the function looks like is this:
Some implementations might have slightly varying semantics, such as whether to always return a result that’s a freshly-minted object, or instead to always modify the first parameter like that one does.
Note also that that’s a shallow copy — to make a complete “deep” copy, you’d need more code.