Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. //création de la classe
  2.  
  3. class Person {
  4. constructor(name, age){
  5. this.name = name ;
  6. this.age = age ;
  7. }
  8. tellMyName(){
  9. console.log(`I am ${this.name}`);
  10. }
  11. tellMyAge(){
  12. console.log(`I am ${this.age} years old.`);
  13. }
  14. }
  15.  
  16. //instance des 2 personnes
  17.  
  18. const John = new Person ('John',40);
  19. const Mary = new Person ('Mary', 35);
  20.  
  21. John.tellMyName();
  22. John.tellMyAge();
  23. Mary.tellMyName();
  24. Mary.tellMyAge();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement