Skip to content

Instantly share code, notes, and snippets.

@mshanemc
Last active May 4, 2017 14:50
Show Gist options
  • Save mshanemc/cc8f3a2ba061891ab2d7559db0c40a97 to your computer and use it in GitHub Desktop.
Save mshanemc/cc8f3a2ba061891ab2d7559db0c40a97 to your computer and use it in GitHub Desktop.
({
rebuildRecord : function(record, describe) {
let testobj = {
apiName: "Account",
fields : {
Name : {
displayValue:null,
value: "Burlington Textiles Corp of America"
}
},
id : "001B000000RTuZ2IAL"
};
//I can do this
testobj.newField = "works fine";
console.log(testobj.newField); // "works fine"
//This works
testobj.fields.Name.addedData = "Fine";
console.log(testobj.fields.Name.addedData);
//This works
testobj.fields['Name'].addedData = "Fine, too";
console.log(testobj.fields['Name'].addedData);
//let's prove that it's not object.assign related
let testobj2 = Object.assign({}, testobj, {});
//This works
testobj2.fields.Name.moreData = "Still Fine after Clone";
console.log(testobj2.fields.Name.moreData);
//now with a clone of data passed in to the function instead of created locally
let testobj3 = Object.assign({}, record, {});
testobj3.newField = "works fine";
console.log(testobj3.newField); // "works fine"
//This works
testobj3.fields.Name.addedData = "Fails";
console.log(testobj3.fields.Name.addedData); //undefined
//This doesn't work
testobj3.fields['Name'].addedData = "Fails, too";
console.log(testobj3.fields['Name'].addedData); //undefined
return testobj;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment