24 lines
316 B
Markdown
24 lines
316 B
Markdown
|
|
|
|
```js
|
|
//+ run demo
|
|
var calculator = {
|
|
sum: function() {
|
|
return this.a + this.b;
|
|
},
|
|
|
|
mul: function() {
|
|
return this.a * this.b;
|
|
},
|
|
|
|
read: function() {
|
|
this.a = +prompt('a?', 0);
|
|
this.b = +prompt('b?', 0);
|
|
}
|
|
}
|
|
|
|
calculator.read();
|
|
alert( calculator.sum() );
|
|
alert( calculator.mul() );
|
|
```
|
|
|