Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <meta charset="UTF-8">
- <title>Symbols_01</title>
- </head>
- <body>
- <script>
- let un_simbolo = Symbol("il primo simbolo");
- let un_altro_simbolo = Symbol("il primo simbolo");
- writeln(un_simbolo === un_altro_simbolo); //false
- writeln( String(un_simbolo) );
- writeln( String(un_altro_simbolo) );
- let oggetto =
- {
- colore: "giallo",
- peso: 21,
- scheda: function () {
- let s = "";
- for (x in this)
- if (x!=="scheda") s += x + " ";
- return s;
- }
- }
- oggetto.check2 = "eee";
- let check = Symbol("il check");
- oggetto[check] = "OK";
- writeln(oggetto[check]);
- writeln( oggetto.scheda() );
- //writeln(oggetto.check) NO usare l`accesso con []
- let report = Symbol();
- let oggetto2 =
- {
- prodotto: "xyz",
- [report]() {return this.prodotto;}
- }
- oggetto2[report] = function () { return "Controllo effettuato!";}
- writeln(oggetto2[report]());
- writeln( String(Object.getOwnPropertySymbols(oggetto)[0]));
- function writeln(messaggio, cornicetta=false)
- {
- document.write(messaggio+"<br>");
- if (cornicetta)
- writeln("-".repeat(40));
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement