Advertisement
fcamuso

Javascript Lezione 64

Aug 6th, 2022 (edited)
1,221
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. 'use strict';
  14.  
  15.     class Auto {
  16.      
  17.       static #conta_auto = 0;
  18.       static get conta_auto() {return this.#conta_auto;}
  19.  
  20.       //fields
  21.       #marca="sconosciuta";
  22.       #modello="sconosciuta";
  23.       #max_velocita = 0;
  24.  
  25.       var_classe_madre="madre";
  26.       get var_classe_madre() {return this.var_classe_madre;}
  27.    
  28.       constructor (marca, modello, massima_velocita) {
  29.        
  30.         if (marca === undefined) throw new Error('Marca non specificata');
  31.  
  32.         this.#marca = marca;
  33.         this.#modello = modello;
  34.  
  35.         this.max_velocita = massima_velocita;
  36.        
  37.         //Object.seal(this);
  38.  
  39.         Auto.#conta_auto++;
  40.       }
  41.  
  42.       #sendMail() {console.log('email inviata')};
  43.  
  44.       //setter tradizionale
  45.       Set_max_velocita(nuovaVelocita){
  46.         if (nuovaVelocita>100) this.#max_velocita = nuovaVelocita;
  47.       }
  48.  
  49.       //getter tradizionale
  50.       Get_max_velocita() {return this.#max_velocita;}
  51.  
  52.       set max_velocita(nuovaVelocita) {
  53.         if (nuovaVelocita>100) this.#max_velocita = nuovaVelocita;
  54.       }
  55.  
  56.       get max_velocita() {return this.#max_velocita;}
  57.  
  58.       Scheda() { return `${this.#marca} - ${this.#modello} - ${this.#max_velocita}`; }
  59.  
  60.     }
  61.  
  62.     class AutoSportiva extends Auto {
  63.  
  64.       etaMinima = 18;
  65.  
  66.       constructor(marca) {
  67.         super(marca);
  68.       }
  69.  
  70.       Scheda() { return  `${super.Scheda()} - ${this.etaMinima} - ${super.var_classe_madre}`};  
  71.  
  72.     }
  73.  
  74.  
  75.     const autoSportiva = new AutoSportiva("Fiat");
  76.     console.log(autoSportiva.Scheda());
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.     // let auto = null;
  90.     // let parco_auto = null;
  91.     // try {
  92.     //   console.log('#'+Auto.conta_auto+'#');
  93.     //   auto = new Auto("Fiat", "500", 120);
  94.     //   parco_auto = [new Auto("Fiat", "500", 120), new Auto("Fiat", "500", 120), new Auto("Fiat", "500", 120)];
  95.  
  96.     //   console.log('#'+Auto.conta_auto+'#');
  97.  
  98.     // }
  99.     // catch (eccezione)
  100.     // {
  101.     //   console.log(eccezione.message);
  102.     // }
  103.  
  104.     // if (auto !==null)
  105.     // {
  106.     //   //auto.#marca = ""; //vietato: field privato
  107.     //   //auto.paperino = "slakjfljfd"; //vietato: oggetto sealed
  108.  
  109.     //   //console.log(auto);
  110.     //   //auto.#sendMail(); //no, privato
  111.  
  112.     //   //auto.Set_max_velocita(130);
  113.  
  114.     //   //auto.max_velocita = 130;
  115.     //   //console.log(auto.max_velocita);
  116.  
  117.  
  118.     //   //auto.Print();
  119.  
  120.     // }
  121.  
  122.   </script>
  123. </body>
  124. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement