Last active
August 29, 2015 14:02
-
-
Save RhinoLance/c3173001268a2370eb49 to your computer and use it in GitHub Desktop.
Replace object properties from other object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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