The extend()
function in the Underscore library is used to copy properties of one or more source objects to a destination object. Here's an example of how to use it:
index.tsx413 chars16 lines
Output:
index.tsx68 chars7 lines
In the above example, we first load the Underscore library and define a destination object destinationObj
. We then define two source objects sourceObj1
and sourceObj2
that contain properties that we want to copy to the destination object. Finally, we call the _.extend()
function to copy the properties of the source objects to the destination object. The modified destinationObj
is printed to the console.
Note that the _.extend()
function modifies the destination object in place and returns it. If two or more source objects contain properties with the same name, the value of the last property in the arguments list will overwrite the previous values.
gistlibby LogSnag