en.javascript.info/1-js/6-objects-more/3-constructor-new/2-calculator-constructor/solution.md
2015-03-10 12:36:58 +03:00

423 B

//+ run demo
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() );