Advertisement
fcamuso

Javascript Lezione 62

Aug 3rd, 2022
1,091
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.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>Classi</title>
  8. </head>
  9. <body>
  10.  
  11.  
  12.   <script>
  13.  
  14.     class Auto {
  15.      
  16.       //fields
  17.       marca="sconosciuta";
  18.       modello="sconosciuta";
  19.       max_velocita = 0;
  20.    
  21.       constructor (marca, modello) {
  22.        
  23.         if (marca === undefined) throw new Error('Marca non specificata');
  24.  
  25.         this.marca = marca;
  26.         this.modello = modello;
  27.       }
  28.     }
  29.  
  30.     //const Moto = class { }
  31.     //const la_mia_auto = new Auto("Fiat", "500");
  32.  
  33.     let auto2 = null;
  34.     try {
  35.       auto2 = new Auto("Fiat");
  36.     }
  37.     catch (eccezione)
  38.     {
  39.       console.log(eccezione.message);
  40.     }
  41.  
  42.     if (auto2 !==null)
  43.       console.log(`${auto2.marca} - ${auto2.modello}`);
  44.  
  45.   </script>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement