Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Person {
  2. constructor(name, age) {
  3. this.name = name;
  4. this.age = age;
  5. }
  6.  
  7. get tellMyName() {
  8. return "I am " + this.name;
  9. }
  10.  
  11. get tellMyAge() {
  12. return "I am " + this.age + " years old."
  13. }
  14. }
  15.  
  16. const john = new Person("John", 40);
  17. const mary = new Person("Mary", 35);
  18.  
  19. console.log(john.tellMyName);
  20. console.log(john.tellMyAge);
  21.  
  22. console.log(mary.tellMyName);
  23. console.log(mary.tellMyAge);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement