this.affiche_velo = affiche_velo;dans la définition du type velo.
<SCRIPT LANGUAGE="JavaScript"> function message(chaine) { document.write("<HR><P>" + chaine); } function montre_proprietes(objet, nom_objet) { var resultat = ""; document.write("<BR>"); for(var i in objet) resultat += nom_objet + "." + i + " = " + objet[i] + "<BR><BR>"; document.write("<BR>"); return resultat; } function personne(prenom, age, taille) { this.prenom = prenom; this.age = age; this.taille = "2m 10, au moins !"; } function velo(marque, vitesses, fourche, proprietaire) { this.marque = marque; this.vitesses = vitesses; this.fourche = fourche; this.proprietaire = proprietaire; this.affiche_velo = affiche_velo; } function affiche_velo() { var resultat = "Un Magnifique " + this.marque + " " + this.vitesses + " " + this.fourche; message(resultat); } moi = new personne("Mathieu", 22, "1m 83"); vtt = new velo("Decathlon", 21, "à suspension", moi); </SCRIPT>
Et si on appelle maintenant la fonction vtt.affiche_velo() :
<SCRIPT LANGUAGE="JavaScript"> vtt.affiche_velo(); </SCRIPT>on obtient :