Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Study</title>
- </head>
- <body>
- <script>
- // this + new version - https://pastebin.com/cirmUYMv
- `use strict`
- function makeCounter() {
- let count = 0;
- return {
- set: function (val) { count = val; },
- get: function () { return count; },
- reset: function () { count = 0; },
- counter: function () { return count++; }
- };
- }
- {
- let counterA = makeCounter();
- counterA.set(26);
- for (let i = 0; i < 5; ++i) { console.log(`counterA.counter() - ${counterA.counter()}`) };
- console.log(`counterA.get() - ${counterA.get()}`);
- let counterB = makeCounter()
- for (let i = 0; i < 5; ++i) { console.log(`counterB.counter() - ${counterB.counter()}`) };
- console.log(`counterB.get() - ${counterB.get()}`);
- counterA.reset();
- counterB.reset();
- console.log(`counterA.get() - ${counterA.get()}`);
- console.log(`counterB.get() - ${counterB.get()}`);
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment