extend()
Extend one object with properties from another object.
Description
Extend one object with properties from another object. Multiple source objects can be specified.
Arguments
- destination : Object
- The object that you want to extend.
- source : Object
- The object that you want to extend the destination object with.
Return Value
Object. Returns the destination object.
Examples
Example 1
We create three objects. Then we extend obj_1 with everything in obj_2 and see that it was added. Then we do the same thing again, but we also see that properties that exist in both objects, get overwritten in the destination object. Finally we create a new object and extend that with both obj_2 and obj_3 and see that the new object get their properties, while the other objects are not changed. Note: The function output() used in this example is a custom function only for this example and is not part of oCanvas.
View Example
Code
var obj_1 = {
foo: "bar"
};
var obj_2 = {
lorem: "ipsum"
};
var obj_3 = {
foo: "foobar",
lorem: "loremipsum"
};
oCanvas.extend(obj_1, obj_2);
output("obj_1: ", obj_1);
oCanvas.extend(obj_3, obj_2);
output("obj_3: ", obj_3);
var newObj = oCanvas.extend({}, obj_2, obj_3);
output("newObj: ", newObj);
output("obj_2: ", obj_2);
Output