Skip to content

Instantly share code, notes, and snippets.

@JoeShep
Created June 8, 2016 15:02
Show Gist options
  • Save JoeShep/b7aff40ffc495f750a7c938236fd543a to your computer and use it in GitHub Desktop.
Save JoeShep/b7aff40ffc495f750a7c938236fd543a to your computer and use it in GitHub Desktop.
Sandwich Maker example
console.log(Sandwich);
var sandwichCost = Sandwich.getSandwichPrice("cheese");
var toppingCost = Sandwich.getToppingPrice("captainCrunch");
var output = document.getElementById("sandwich");
output.innerHTML = sandwichCost + toppingCost;
var Sandwich = (function() {
var prices = {"pb&j": 2.00, "cheese": .75};
return {
getSandwichPrice: function(sandwich) {
return prices[sandwich];
}
};
})();
var Sandwich = (function(origSand) {
var toppingPrices = {"whippedCream": .50, "captainCrunch": .10};
origSand.getToppingPrice = function(topping) {
return toppingPrices[topping];
}
return origSand;
})(Sandwich);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment