Exécuter
❯
Exécuter le code
Ctrl+Alt+R
Sauvegarder le code
Ctrl+Alt+A
Changer d'orientation
Ctrl+Alt+O
Changer de thème
Ctrl+Alt+D
<!DOCTYPE html> <html> <body> <h1>Objets JavaScript</h1> <h2>Constructeurs d'objets</h2> <p id="demo"></p> <script> // Fonction constructeur pour les objets Person function Person(prénom, nom, âge, œil) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; this.nationality = "Anglais"; } // Créer 2 objets Person const myFather = new Person("John", "Doe", 50, "blue"); const myMother = new Person("Sally", "Rally", 48, "green"); // Afficher la nationalité document.getElementById("demo").innerHTML = "Mon père est " + myFather.nationality + ". Ma mère est " + myMother.nationality; </script> </body> </html>