Advertisement
fcamuso

Javascript Lezione 46

Jun 5th, 2022
1,583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   <script>
  2.  
  3.     const unaData = {
  4.         gg: 2,
  5.         mm: 6,
  6.         aa: 2028,
  7.  
  8.         getMonth: function () {return this.mm},
  9.         bisestile: function () {return this.aa%4==0}
  10.     }
  11.  
  12.  
  13.  
  14.     // console.log(unaData.getMonth());
  15.     // if (unaData.bisestile())
  16.     //     console.log(`Febbraio ${unaData.aa} avra' 29 giorni`);      
  17.     // else
  18.     //     console.log(`Febbraio ${unaData.aa} avra' 28 giorni`);
  19.    
  20.     //    const libroArray = [
  21.     //        'I promessi sposi',
  22.     //        'Alessandro',
  23.     //        'Manzoni',
  24.     //        1103,
  25.     //        1825
  26.     //    ];
  27.  
  28.     //    const libroOggetto = {
  29.     //     titolo: 'I promessi sposi',
  30.     //     nomeAutore: 'Alessandro',
  31.     //     cognomeAutore: 'Manzoni',
  32.     //     pagine: 1103,
  33.     //     primaEdizione: 1825
  34.     //    }
  35.  
  36.     //    //console.log(libroOggetto.cognome-Autore);
  37.     //    console.log(libroOggetto["cognome-Autore"]);
  38.     //    console.log(libroOggetto.hasOwnProperty('pagine'));
  39.  
  40.     function MyDate(g=1, m=1, a=1970) {
  41.       this.gg = g;
  42.       this.mm = m;
  43.       this.aa = a;
  44.  
  45.       this.getMonth = function () {return this.mm;};
  46.       this.bisestile = function () {return this.aa%4==0}
  47.  
  48.       return "valore restituito";
  49.     }
  50.  
  51.     const data1 = new MyDate(4,6,2022);
  52.     const data2 = new MyDate();
  53.  
  54.     Object.seal(data2);
  55.  
  56.     // data2.NuovaProperty = "xxxxx";
  57.     // data2.NuovaFunzione = function () {console.log("nuova funzione");}
  58.     // console.log(data2.NuovaProperty);
  59.     // data2.NuovaFunzione();
  60.     // data2.g = 12;
  61.  
  62.     Object.seal(MyDate.prototype);
  63.     MyDate.prototype.nuovaProperty="yyyyy";
  64.     console.log(MyDate.prototype.nuovaProperty);
  65.  
  66.     const data3 = new MyDate();
  67.     console.log(data3.nuovaProperty);
  68.     console.log(data2.nuovaProperty);
  69.  
  70.  
  71.  
  72.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement