var HAMBURGER = {
SIZE_BIG: {price: 100, caloric: 40},
SIZE_SMALL: {price: 50, caloric: 20},
STUFFING_CHEESE: {price: 10, caloric: 20},
STUFFING_SALAD: {price: 20, caloric: 5},
STUFFING_POTATOES: {price: 15, caloric: 10},
TOPPING_SAUCE: {price: 15, caloric: 0},
TOPPING_MAYO: {price: 20, caloric: 5}
};
function Hamburger(size, stuffing) {
var price = size.price + stuffing.price;
var caloric = size.caloric + stuffing.caloric;
this.addTopping = function (topping) {
price += topping.price;
caloric += topping.caloric;
}
this.calculateCalories = function () {
return caloric;
}
this.calculatePrice = function () {
return price;
}
}
// маленький гамбургер с начинкой из сыра
var hamburger = new Hamburger(HAMBURGER.SIZE_SMALL, HAMBURGER.STUFFING_CHEESE);
// добавка из майонеза
hamburger.addTopping(HAMBURGER.TOPPING_MAYO);
// спросим сколько там калорий
console.log("Calories: %f", hamburger.calculateCalories());
// сколько стоит
console.log("Price: %f", hamburger.calculatePrice());
// я тут передумал и решил добавить еще приправу
hamburger.addTopping(HAMBURGER.TOPPING_SAUCE);
// А сколько теперь стоит?
console.log("Price with sauce: %f", hamburger.calculatePrice());
dmFyIEhBTUJVUkdFUiA9IHsKCVNJWkVfQklHOiB7cHJpY2U6IDEwMCwgY2Fsb3JpYzogNDB9LCAKCVNJWkVfU01BTEw6IHtwcmljZTogNTAsIGNhbG9yaWM6IDIwfSwgCgoJU1RVRkZJTkdfQ0hFRVNFOiB7cHJpY2U6IDEwLCBjYWxvcmljOiAyMH0sIAoJU1RVRkZJTkdfU0FMQUQ6IHtwcmljZTogMjAsIGNhbG9yaWM6IDV9LAoJU1RVRkZJTkdfUE9UQVRPRVM6IHtwcmljZTogMTUsIGNhbG9yaWM6IDEwfSwgCgoJVE9QUElOR19TQVVDRToge3ByaWNlOiAxNSwgY2Fsb3JpYzogMH0sIAoJVE9QUElOR19NQVlPOiB7cHJpY2U6IDIwLCBjYWxvcmljOiA1fQp9OwoKCmZ1bmN0aW9uIEhhbWJ1cmdlcih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