Exécuter
❯
Exécuter le code
Ctrl+Alt+R
Enregistrer 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>Ajouter une propriété à un constructeur</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; } // Créer 2 objets Personne const myFather = new Person("John", "Doe", 50, "blue"); const myMother = new Person("Sally", "Rally", 48, "green"); // Ajouter une nouvelle Propriété Person.prototype.nationality = "Anglais"; // Afficher nouvelle Propriété document.getElementById("demo").innerHTML = "La nationalité de mon père est " + myFather.nationality; </script> </body> </html>