en.javascript.info/1-js/4-object-basics/05-constructor-new/2-calculator-constructor/solution.md
Ilya Kantor 4c531b5ae7 ok
2016-07-31 00:28:27 +03:00

419 B

function Calculator() {

  this.read = function() {
    this.a = +prompt('a?', 0);
    this.b = +prompt('b?', 0);
  };

  this.sum = function() {
    return this.a + this.b;
  };

  this.mul = function() {
    return this.a * this.b;
  };
}

var calculator = new Calculator();
calculator.read();

alert( "Сумма=" + calculator.sum() );
alert( "Произведение=" + calculator.mul() );