Skip to content

Instantly share code, notes, and snippets.

@vjwilson
Created April 29, 2020 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjwilson/fdb1fadba91d1bc77e509230963a85ca to your computer and use it in GitHub Desktop.
Save vjwilson/fdb1fadba91d1bc77e509230963a85ca to your computer and use it in GitHub Desktop.
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>
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