Example of use: mergeObjects()
Both the objWebParam and options "object" contain an .objReturn property - which is an object.
The .objReturn "object" contains just value properties (string, numeric, boolean). It does NOT contain properties that are array or objects themselves.
Any "property" found in options.objReturn that does not already exist in objWebParam.objReturn will be created with that value copied.
Code:mergeObjects(objWebParam.objReturn, options.objReturn);
Example of use: matchObjects()
Comparing two .objReturn objects. These objects contain just value properties (string, numeric, boolean) allowing this simple function to work.
Code:blnMatchSproc = matchObjects(gaSprocs[i].what.options.objReturn, objOptions.objReturn);
Example of use: mergeObjectsDeep(), mergeObjectsShallow() and mergeObjectsArray()
This example is cloning a complex array element into a new slot in that same array. This is an array of objects.
I am retaining the length, pushing a new object on, and then taking the [i] slot of the array and then cloning it's many members.
A more intimate knowledge of the property types of the cloned object are needed so you can navigatee the many ways to move properties (you will notice I use just .slice() in places where a simple array is being moved or intentionally leaving it off to "force" a connection to the original array).
Code:gmOffset = g_objGMaker.length; g_objGMaker.push({ status: "clone", clone: i, gm: gmOffset, gname: sName, filterTab: -1, gmProperties: {}, parentInfo: {}, gmSource: {} }); g_objGMaker[gmOffset].gmSource.sourceOrig = g_objGMaker[i].gmSource.sourceOrig; g_objGMaker[gmOffset].gmSource.sourceOutput = g_objGMaker[i].gmSource.sourceOutput.slice(0); g_objGMaker[gmOffset].gmSource.sourceOutput.gm = gmOffset; mergeObjectsDeep(g_objGMaker[gmOffset].parentInfo, g_objGMaker[i].parentInfo); g_objGMaker[gmOffset].parentInfo.original = false; mergeObjectsShallow(g_objGMaker[gmOffset].gmProperties, g_objGMaker[i].gmProperties); mergeObjectsShallow(g_objGMaker[gmOffset].gmProperties.settingsObj, g_objGMaker[i].gmProperties.settingsObj); mergeObjectsShallow(g_objGMaker[gmOffset].gmProperties.curGraph, g_objGMaker[i].gmProperties.curGraph); for (var j = 0; j < g_objGMaker[i].gmProperties.arrFilters.length; j++) { g_objGMaker[gmOffset].gmProperties.arrFilters.push({}); mergeObjectsShallow(g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1], g_objGMaker[i].gmProperties.arrFilters[j]); g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1].alphaCountList = g_objGMaker[i].gmProperties.arrFilters[j].alphaCountList.slice(0); mergeObjects(g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1].alphaCountUsage, g_objGMaker[i].gmProperties.arrFilters[j].alphaCountUsage); g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1].dataList = g_objGMaker[i].gmProperties.arrFilters[j].dataList.slice(0); mergeObjects(g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1].dataUsage, g_objGMaker[i].gmProperties.arrFilters[j].dataUsage); mergeObjectsArray(g_objGMaker[gmOffset].gmProperties.arrFilters[g_objGMaker[gmOffset].gmProperties.arrFilters.length - 1].filter, g_objGMaker[i].gmProperties.arrFilters[j].filter); } if (g_objGMaker[gmOffset].gmProperties.settingsObj.colsum) { mergeObjectsArray(g_objGMaker[gmOffset].gmProperties.settingsObj.colsum, g_objGMaker[i].gmProperties.settingsObj.colsum); } if (g_objGMaker[gmOffset].gmProperties.settingsObj.selectedcols) { mergeObjectsArray(g_objGMaker[gmOffset].gmProperties.settingsObj.selectedcols, g_objGMaker[i].gmProperties.settingsObj.selectedcols); } if (g_objGMaker[gmOffset].gmProperties.settingsObj.arrcontrol) { g_objGMaker[gmOffset].gmProperties.settingsObj.arrcontrol = g_objGMaker[i].gmProperties.settingsObj.arrcontrol.slice(0); } if (g_objGMaker[gmOffset].gmProperties.settingsObj.columns) { g_objGMaker[gmOffset].gmProperties.settingsObj.columns = g_objGMaker[i].gmProperties.settingsObj.columns.slice(0); } if (g_objGMaker[gmOffset].gmProperties.messagepump) { g_objGMaker[gmOffset].gmProperties.messagepump = g_objGMaker[i].gmProperties.messagepump.slice(0); }




Reply With Quote