Last active
April 16, 2018 14:07
context
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
// pythontutor this code | |
var cleancalc = { | |
lastResult: null, | |
add: function (arg1, arg2) { | |
return arg1 + arg2; | |
}, | |
operate: function (operation, arg1, arg2) { | |
if (arg2) { | |
return this.lastResult = this[operation](arg1, arg2); | |
} else { | |
return this.lastResult = this[operation](arg1, this.lastResult); | |
} | |
return "oops" | |
} | |
} | |
cleancalc.operate("add", 2, 3) | |
cleancalc.operate("add", 2) |
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
let thissing = { | |
variable: "inside", | |
print: function() { | |
console.log(variable); | |
console.log(this.variable); | |
} | |
} | |
let variable = "outside" | |
thissing.print() | |
// use pythontutor |
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
let greeter = { | |
english: 'Welcome', | |
czech: 'Vitejte', | |
danish: 'Velkomst', | |
greet: function(language) { | |
if (this[language] !== undefined) { | |
console.log(this[language]); | |
} else { | |
console.log("XXX"); | |
} | |
} | |
} | |
var errg = "english" | |
console.log(greeter[errg]) | |
greeter.greet(errg) |
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
let sushiroll = { | |
ingredients: { | |
dolphin: true, | |
rice: true, | |
mayonaise: false | |
}, | |
is_inhumane: function(ingredient) { | |
if (this.ingredients[ingredient] != undefined) { | |
return this.ingredients[ingredient]; | |
} else { | |
return "does not contain this ingredient" | |
} | |
}, | |
bad_practice: function(ingredient) { | |
if (sushiroll.ingredients[ingredient] != undefined) { | |
return sushiroll.ingredients[ingredient]; | |
} else { | |
return "does not contain this ingredient" | |
} | |
} | |
} | |
console.log(sushiroll.is_inhumane("dolphin")) | |
console.log(sushiroll.bad_practice("dolphin")) | |
console.log(sushiroll.is_inhumane("rice")) | |
console.log(sushiroll.is_inhumane("mayonaise")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment