Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Classi</title>
- </head>
- <body>
- <script>
- class Auto {
- //fields
- marca="sconosciuta";
- modello="sconosciuta";
- max_velocita = 0;
- constructor (marca, modello) {
- if (marca === undefined) throw new Error('Marca non specificata');
- this.marca = marca;
- this.modello = modello;
- }
- }
- //const Moto = class { }
- //const la_mia_auto = new Auto("Fiat", "500");
- let auto2 = null;
- try {
- auto2 = new Auto("Fiat");
- }
- catch (eccezione)
- {
- console.log(eccezione.message);
- }
- if (auto2 !==null)
- console.log(`${auto2.marca} - ${auto2.modello}`);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement