Advertisement
fcamuso

Javascript Lezione 69

Aug 17th, 2022
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <head>
  3.   <meta charset="UTF-8">
  4.   <title>Symbols_01</title>
  5. </head>
  6. <body>
  7.   <script>
  8.      let un_simbolo = Symbol("il primo simbolo");
  9.      let un_altro_simbolo = Symbol("il primo simbolo");
  10.  
  11.      writeln(un_simbolo === un_altro_simbolo); //false
  12.      writeln( String(un_simbolo) );
  13.      writeln( String(un_altro_simbolo) );
  14.  
  15.       let oggetto =
  16.       {
  17.         colore: "giallo",
  18.         peso: 21,
  19.  
  20.         scheda: function () {
  21.           let s = "";
  22.           for (x in this)
  23.             if (x!=="scheda") s += x + " ";
  24.           return s;
  25.         }
  26.  
  27.       }
  28.      
  29.       oggetto.check2 = "eee";
  30.  
  31.       let check = Symbol("il check");
  32.       oggetto[check] = "OK";
  33.  
  34.       writeln(oggetto[check]);
  35.       writeln( oggetto.scheda() );
  36.       //writeln(oggetto.check) NO usare l`accesso con []
  37.  
  38.       let report = Symbol();
  39.       let oggetto2 =
  40.       {
  41.           prodotto: "xyz",
  42.           [report]() {return this.prodotto;}
  43.  
  44.       }
  45.       oggetto2[report] = function () { return "Controllo effettuato!";}
  46.  
  47.       writeln(oggetto2[report]());
  48.       writeln( String(Object.getOwnPropertySymbols(oggetto)[0]));
  49.  
  50.  
  51.   function writeln(messaggio, cornicetta=false)
  52.   {
  53.      document.write(messaggio+"<br>");
  54.      if (cornicetta)
  55.        writeln("-".repeat(40));
  56.   }
  57.        
  58.    </script>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement