'use strict';
var small = {
price: 50,
cl: 20,
};
var big = {
price: 100,
cl: 40,
}
var Staff = function(price, cl) {
this.price = price;
this.cl = cl;
};
var Hamburger = function(price, cl, stuff, flavoring) {
if (!((price == small.price && cl ==small.cl) || (price == big.price && cl == big.cl))) {
throw 'Hanburger type was not recognized';
}
this.price = price;
this.cl = cl;
this.add_stuff(stuff);
if (flavoring) {
this.add_stuff(flavoring);
}
};
Hamburger.prototype.toString = function() {
return 'Price: ' + this.price + ' Cl: ' + this.cl;
};
Hamburger.prototype.add_stuff = function(stuff) {
this.price += stuff.price;
this.cl += stuff.cl;
};
function createHumburger(size, stuff, extra_stuff) {
var h = new Hamburger(size.price, size.cl, stuff, extra_stuff);
console.log(h);
}
var s = new Staff(10, 20);
var f = new Staff(15, 0);
createHumburger(small, s, f);
// http://i...content-available-to-author-only...e.com/4pMXyV
// Посоны, проверьте про гамбургеры задание. И еще скажите как реализовать функцию bind. Я не втыкаю что-то.
J3VzZSBzdHJpY3QnOwoKCnZhciBzbWFsbCA9IHsKICAgIHByaWNlOiA1MCwKICAgIGNsOiAyMCwKfTsKCnZhciBiaWcgPSB7CiAgICBwcmljZTogMTAwLAogICAgY2w6IDQwLAp9CgoKdmFyIFN0YWZmID0gZnVuY3Rpb24ocHJpY2UsIGNsKSB7CiAgICB0aGlzLnByaWNlID0gcHJpY2U7CiAgICB0aGlzLmNsID0gY2w7Cn07Cgp2YXIgSGFtYnVyZ2VyID0gZnVuY3Rpb24ocHJpY2UsIGNsLCBzdHVmZiwgZmxhdm9yaW5nKSB7CgogICAgaWYgKCEoKHByaWNlID09IHNtYWxsLnByaWNlICYmIGNsID09c21hbGwuY2wpIHx8IChwcmljZSA9PSBiaWcucHJpY2UgJiYgY2wgPT0gYmlnLmNsKSkpIHsKICAgICAgICB0aHJvdyAnSGFuYnVyZ2VyIHR5cGUgd2FzIG5vdCByZWNvZ25pemVkJzsKICAgIH0KCiAgICB0aGlzLnByaWNlID0gcHJpY2U7CiAgICB0aGlzL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