D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
vjwilson
Full window
Github gist
JS Bin // source https://jsbin.com/mebinir
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> const instructions = [ { type: 'REPLACE_NAME', value: '' } ] function runCommands(commands, obj) { const newObj = Object.assign({}, obj) commands.forEach(function(com) { switch(com.type) { case 'REPLACE_NAME': { newObj.name = com.value break; } default: { break; } } }) return newObj } const o1 = { name: 'Frodo' } const o2 = runCommands(instructions, o1) console.log(o1) console.log(o2) </script> <script id="jsbin-source-javascript" type="text/javascript">const instructions = [ { type: 'REPLACE_NAME', value: '' } ] function runCommands(commands, obj) { const newObj = Object.assign({}, obj) commands.forEach(function(com) { switch(com.type) { case 'REPLACE_NAME': { newObj.name = com.value break; } default: { break; } } }) return newObj } const o1 = { name: 'Frodo' } const o2 = runCommands(instructions, o1) console.log(o1) console.log(o2) </script></body> </html>