Skip to content

Instantly share code, notes, and snippets.

@RhinoLance
Last active August 29, 2015 14:02
Show Gist options
  • Save RhinoLance/c3173001268a2370eb49 to your computer and use it in GitHub Desktop.
Save RhinoLance/c3173001268a2370eb49 to your computer and use it in GitHub Desktop.
Replace object properties from other object
var setObjectOptions = function(element, args){
var targetObj = allObjects[element];
for (var prop in args) {
// important check that this is objects own property
// not from prototype prop inherited
if(args.hasOwnProperty(prop)){
targetObj[prop] = args[prop];
}
}
}
allObjects = {
elbow_1:{type:'elbow', version:'topLeft', id:'elbow_1', color:'grey'},
btn_alertStatus:{type:'button', id:'btn_alertStatus', color:'blue', label:'Blue Alert'}
}
console.log( JSON.stringify(allObjects));
args = {color:'red', label:'Red Alert'}
setObjectOptions('btn_alertStatus', args);
console.log( JSON.stringify(allObjects));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment