Extends the target object by copying properties from source objects.
const target = { a: 1 };
const source = { b: 2 };
$.assign(target, source);
// target is now:
{ a: 1, b: 2 }
const defaults = { theme: { color: 'blue', font: 'arial' } };
const options = { theme: { color: 'red' } };
// Pass true for deep merge
const final = $.assign(true, {}, defaults, options);
// final object:
{
theme: {
color: 'red',
font: 'arial'
}
}
const obj = $.assign({}, {a:1}, {b:2}, {c:3});
{ a: 1, b: 2, c: 3 }
| Parameter | Type | Description |
|---|---|---|
| deep | boolean | Optional. If true, the merge becomes recursive (deep copy). |
| target | object | The object to receive the new properties. |
| ...sources | object | One or more objects containing the properties to merge. |
Returns: The modified target object.