par , 15/03/2015 à 10h55 (562 Affichages)
![Citation](https://forum.developpez.be/images/misc/quote_icon.png)
Envoyé par
yahiko
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| interface FruitExotique {
exotique: string;
}
var person = {
name: 'Colleen',
age: 25,
getPets: function () {
return ['Spot', 'Nemo', 'Pascal'];
},
listeFruits : ['pomme','poire','banane',{exotique:'mangue'}],
passion: null
};
console.log(person.name);
console.log(person.getPets()[1]);
person.passion = 'natation';
console.log(person.passion);
console.log(person.listeFruits[0]);
console.log((<FruitExotique>person.listeFruits[3]).exotique); |
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
| class Person {
name;
fruits;
age;
passion;
constructor(name:string,fruits:Object, age:any,passion:string[]=[]) {
this.name = name;
this.fruits = fruits;
this.age = age;
this.passion=passion;
}
}
var marie = new Person('Marie',['pomme','poire','banane',{exotique:'mangue'}],'1an');
console.log(marie.fruits[0]);
console.log(marie.fruits[3].exotique);
console.log(marie.age);
marie.passion = ['velo','alpinisme'];
console.log(marie.passion[1]);
console.log('***');
var tarik = new Person('Tarik','cerise',99,['Tshirt','Stylo','Peigne']);
console.log(tarik.name);
console.log(tarik.fruits);
console.log(tarik.age);
console.log(tarik.passion[2]); |
1 2 3 4 5 6 7 8 9
| "pomme"
"mangue"
"1an"
"alpinisme"
"***"
"Tarik"
"cerise"
99
"Peigne" |