extend

merges the contents of 2 objects together into the first object

object extend(object target,object source, [boolean overwrite] );

Parameters

targetobjectthe object to extend. It receives the new properties
sourceobjectan object that contains properties to merge in
overwritebooleanif the value is true, the same properties will be overwritten by the values of the source object

Returns

objectthe target object with the new properties

Example

var obj1 = {name:"flower", type:"rose", colors: ['red','pink','white','yellow']}
var obj2 = {name:"flower", type:"tulip" }
 
webix.extend(obj2,obj1); 
// -> obj2 = {name:"flower", type:"tulip", colors: ['red','pink','white','yellow']}
 
 
obj2.type = 'camomile';
obj2.type // -> 'camomile'
obj1.type // -> 'rose'
 
 
obj2.colors[0] = 'blue';
obj2.colors // -> ['blue','pink','white','yellow']
obj1.colors // -> ['blue','pink','white','yellow']
 
 
obj1 = {name:"flower", type:"rose", colors: ['red','pink','white','yellow']  }
obj2 = {name:"flower", type:"tulip" }
 
webix.extend(obj2,obj1, true); 
// -> obj2 = {name:"flower", type:"rose", colors: ['red','pink','white','yellow']}

See also
Back to top