avr39ripe

jsThisNewDemo

Mar 8th, 2021 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <script>
  9. // Closure version - https://pastebin.com/81212hiK
  10.  
  11.         `use strict`
  12.         function Counter() {
  13.             this.count = 0;
  14.             this.set = function (val) { this.count = val; };
  15.             this.get = function () { return this.count; };
  16.             this.reset = function () { this.count = 0; };
  17.             this.counter = function () { return this.count++; };
  18.         }
  19.  
  20.         {
  21.             let counterA = new Counter();
  22.             counterA.set(26);
  23.             for (let i = 0; i < 5; ++i) { console.log(`counterA.counter() - ${counterA.counter()}`) };
  24.             console.log(`counterA.get() - ${counterA.get()}`);
  25.  
  26.             let counterB = new Counter()
  27.             for (let i = 0; i < 5; ++i) { console.log(`counterB.counter() - ${counterB.counter()}`) };
  28.             console.log(`counterB.get() - ${counterB.get()}`);
  29.  
  30.             counterA.reset();
  31.             counterB.reset();
  32.             console.log(`counterA.get() - ${counterA.get()}`);
  33.             console.log(`counterB.get() - ${counterB.get()}`);
  34.         }
  35.     </script>
  36. </body>
  37. </html>
Add Comment
Please, Sign In to add comment