Instantly share code, notes, and snippets.

Embed
What would you like to do?
context
// 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)
let thissing = {
variable: "inside",
print: function() {
console.log(variable);
console.log(this.variable);
}
}
let variable = "outside"
thissing.print()
// use pythontutor
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)
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