Skip to content

Instantly share code, notes, and snippets.

@billybonks
Created November 21, 2012 17:06
Show Gist options
  • Save billybonks/4126084 to your computer and use it in GitHub Desktop.
Save billybonks/4126084 to your computer and use it in GitHub Desktop.
this function will merge two objects dependent on a path
/*
given that
ObjectA = sourceObject
ObjectB = destinationObject
it will fill Object b with the field in Object A
ObjectA{
SomeField.InnerField : data
}
ObjectB{
SomeField{
InnerField : data
}
}
*/
function MergeObjects (sourceObject,destinationObject){
for(field in sourceObject){
var path = field.split('.');
var destinationpathObject = 'destinationObject'
for(subpath in path){
destinationpathObject+='["'+[path[subpath]]+'"]';
}
//destinationObject[AssignedTo][Name];
eval(destinationpathObject + " = sourceObject[field]")// = sourceObject[field];
}
return destinationObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment