Created
April 29, 2020 11:51
-
-
Save vjwilson/fdb1fadba91d1bc77e509230963a85ca to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/mebinir
This file contains 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
<!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> |
This file contains 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment