17 lines
280 B
Markdown
17 lines
280 B
Markdown
|
|
|
|
```js run demo
|
|
function Accumulator(startingValue) {
|
|
this.value = startingValue;
|
|
|
|
this.read = function() {
|
|
this.value += +prompt('How much to add?', 0);
|
|
};
|
|
|
|
}
|
|
|
|
let accumulator = new Accumulator(1);
|
|
accumulator.read();
|
|
accumulator.read();
|
|
alert(accumulator.value);
|
|
```
|