Skip to content

Instantly share code, notes, and snippets.

@colevandersWands
Last active April 16, 2018 14:07
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 colevandersWands/cc8097b59102042a878bdc9b6df89012 to your computer and use it in GitHub Desktop.
Save colevandersWands/cc8097b59102042a878bdc9b6df89012 to your computer and use it in GitHub Desktop.
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