Skip to content

Instantly share code, notes, and snippets.

@Louiefigz
Created December 12, 2016 18:13
Show Gist options
  • Save Louiefigz/a6364ea650465c1cc1ba3719dcc055be to your computer and use it in GitHub Desktop.
Save Louiefigz/a6364ea650465c1cc1ba3719dcc055be to your computer and use it in GitHub Desktop.
function Sandwich(bread, ingredients, name) {
this.bread = bread;
this.ingredients = ingredients;
this.name = name;
}
function serve(customer) {
// From the variable gc, we have access to this.name
console.log("Hey " + customer + ", here's your " + this.name + ", enjoy!");
}
var gc = new Sandwich("white", ["cheese"], "Grilled Cheese");
var pbj = new Sandwich("wheat", ["peanut butter", "raspberry jam"],
"Peanut Butter & Jelly");
// the second argument here is the 'customer' variable that is used in serve().
// the first argumement here is the object that we are creating.
serve.call(gc, "Terry");
serve.call(pbj, "Jesse");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment