Advertisement
piffy

3.3.8 Es 8

Aug 29th, 2021
1,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.69 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>Classe Quadrato</title>
  6.   <script>
  7.     class Quadrato {
  8.       constructor(lato) { this._lato = lato;  }
  9.  
  10.       get lato() { return this._lato; }
  11.  
  12.       get area() { return this._lato*this._lato;      }
  13.  
  14.       get perimetro() { return this._lato*4; }
  15.  
  16.       set lato(l) { this._lato = l; }
  17.  
  18.     }
  19.    const quadrato = new Quadrato(3);
  20.     console.log(quadrato.lato); // --> 3
  21.     console.log(quadrato.area);  // --> 9
  22.     console.log(quadrato.perimetro);  // --> 9
  23.     quadrato.lato=4;
  24.     console.log(quadrato.area);  // --> 16
  25.  
  26.  
  27.   </script>
  28. </head>
  29. <body>
  30. <p>Consultare la console.</p>
  31. </body>
  32. </html>
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement