1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/dojotoolkit/dojo/dojo.js"></script>
<script type="text/javascript">
djConfig="parseOnLoad: true, isDebug: true";
dojo.declare(
"Personne",
null,
{
nom: "",
prenom : "",
constructor: function(args /*objet {nom: XXXX, prenom: XXXX} */) {
args = args || {};
dojo.mixin(this, args);
//if (args.nom) { ... }
/* ou
this.nom = args.nom;
this.prenom = args.prenom;
*/
},
}
);
dojo.declare(
"Footballeur",
Personne,
{
constructor: function(args /* objet { nom: XXXX, prenom: XXXX, equipe: XXXX } */) {
this.equipe = args.equipe;
},
}
);
dojo.declare(
"Avatar",
null,
{
constructor: function(args /* { energie: XXX } */) {
this.energie = args.energie;
},
}
);
dojo.declare(
"Personnage",
[Personne, Avatar],
{
constructor: function(args /*objet { nom : XXXX, prenom:XXXX, energie:XXXXX, monde:XXXXX } */) {
this.monde = args.monde;
}
}
);
dojo.addOnLoad(
function(){
//création d'une personne avec nom et prenom
var canto = new Personne({nom:"Cantona",prenom:"Eric"});
console.log(canto);
//Via l'héritage, on ajoute l'équipe
var canto2 = new Footballeur({nom:"Cantona",prenom:"Eric", equipe:"Manchester United"});
console.log(canto2);
//finalement un Personnage correct
var canto4 = new Personnage({nom:"Cantona",prenom:"Eric", monde:"Football", energie:123});
console.log(canto4);
});
</script>
</head>
<body>
<p>Hello world !</p>
</body>
</html> |