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>
- // Closure version - https://pastebin.com/81212hiK
- `use strict`
- function Counter() {
- this.count = 0;
- this.set = function (val) { this.count = val; };
- this.get = function () { return this.count; };
- this.reset = function () { this.count = 0; };
- this.counter = function () { return this.count++; };
- }
- {
- let counterA = new Counter();
- counterA.set(26);
- for (let i = 0; i < 5; ++i) { console.log(`counterA.counter() - ${counterA.counter()}`) };
- console.log(`counterA.get() - ${counterA.get()}`);
- let counterB = new Counter()
- 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