Skip to main content

extend

Extend an object by appending all of the properties from each supplied object. When there are identical properties, the right-most property takes precedence. This function returns a mutable object reference which is a reference to the first supplied object.

Signature

extend<T>(object: T, ...objects: T[]): T

Parameters

NameTypeOptionalDescription
objectTNoSpecifies the object to extend.
objectsT[]NoSpecifies the objects to extend with.

Return value

Returns the extended mutable object which is a reference to object.

Example

import { extend } from "@tripetto/builder";

const xyz = { a: 1, b: 2 };

extend(xyz, { b: 3, d: 4 }, { d: 5 }); // Returns a reference to `xyz` that now contains `{ a: 1, b: 3, d: 5 }`