Javascript: Créer son propre objet

Author:

Javascript: Créer son propre objet
Download

<html><head>
 
</head>
<body>
  <script language="javascript">
 
function printAll( ) 
{
    document.write("<br />Employé " + this.nom + " à " + this.age + " ans.");    
}
// Définir un objet avec deux propriétés
function employes(nom, age) 
{
    this.nom = nom;
    this.age = age;
    this.show = printAll;
}
// Invoquer l'objet créé 
var emp1 = {nom:"Bill", age:23, show:printAll};
var emp2 = {nom:"Steve", age:32, show:printAll};
 
// Afficher les valeurs des objets
emp1.show( );
emp2.show( );
 
/*
Employé Bill à 23 ans.
Employé Steve à 32 ans. 
*/
     </script>
 </body>
</html>

Cet article Javascript: Créer son propre objet est apparu en premier sur .