Created
May 2, 2018 17:56
-
-
Save denispeyrusaubes/acaf98f6567670b94a65cebc86dd9837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#1: Voiture avec des propriétés publiques | |
class Voiture1 { | |
couleur: string; | |
vitesseMax: number; | |
constructor(c: string, v: number) { | |
this.couleur = c; | |
this.vitesseMax = v; | |
} | |
getDescription() { | |
return this.couleur + ' ' + this.vitesseMax; | |
} | |
} | |
var voiture1 = new Voiture1('Rouge', 250); | |
alert(voiture1.getDescription()); | |
//#2: Déclarer des propriétés directement dans le constructeur | |
class Voiture2 { | |
constructor(public couleur: string, public vitesseMax: number) { | |
} | |
getDescription() { | |
return this.couleur + ' ' + this.vitesseMax; | |
} | |
} | |
var voiture2 = new Voiture2('blanche', 120); | |
alert(voiture2.getDescription()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment