en.javascript.info/01-js/06-objects-more/02-constructor-new/02-calculator-constructor/solution.md
Ilya Kantor f301cb744d init
2014-10-26 22:10:13 +03:00

424 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() );