extend :: Object

Object.extend(dest, src) -> alteredDest Copies all properties from the source to the destination object. Used by Prototype to simulate inheritance (rather statically) by copying to prototypes.

The Object.extend function amends an object with the properties of a second object, effectivly combining them.

Object.extend(objA, objB); // Amends objA with objB

The function also returns the changed objA for direct usage in an assignment or function call.

Properties in objB override properties of the same name in objA.

A common use for Object.extend() in script.aculo.us is to update default options with user-supplied overrides.

Examples

Basic usage:

objA = {name: "Joe", age: "12"};

objB = {name: "Tom"};

Object.extend(objA, objB);

objA.name

// -> "Tom"

Usage with assignment:

objA = {name: "Joe", age: "12"};

objC = Object.extend(objA, {name: "Tom"});

objD = Object.extend(objA, {name: "Jim"});

objC.name

// -> "Tom"

objD.name

// -> "Jim"

// Note that objA always gets changed

objA.name

// -> "Jim

Notes

These official documentation is not fully completed yet. These above are taken from the script.aculo.us wike and created by Thomas Fuchs.

Do not mistake this method with its quasi-namesake Element.extend, which implements Prototype’s (much more complex) DOM extension mechanism.

Prototype API 1.5.0 - prototypejs.org