Ivankooo1

Person

Sep 25th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class Person {
  2. static type = 'Homo Sapiens';
  3. #currentAge;
  4. prop = 'value';
  5.  
  6. constructor(firstName, lastName, age) {
  7. this.firstName = firstName;
  8. this.lastName = lastName;
  9. this.age = age || 0;
  10. }
  11.  
  12. get fullName() {
  13. return this.firstName + ' ' + this.lastName;
  14. }
  15.  
  16. get age() {
  17. return this.#currentAge;
  18. }
  19.  
  20. set age(value) {
  21. if (!(value < 0 || value > 120)) {
  22. this.#currentAge = value;
  23. }
  24. }
  25.  
  26. static talk() {
  27. console.log('Blablablalba' + this.prop);
  28. }
  29.  
  30. talk() {
  31. console.log('asdas1111');
  32. }
  33.  
  34. greet() {
  35. console.log('Hello, my name is ');
  36. }
  37. }
  38.  
  39. let person1 = new Person('Pesho', 'Petrov');
  40. let person2 = new Person('Gosho', 'Ivanov', 22);
  41.  
  42. Person.talk()
  43. person1.talk();
Advertisement
Add Comment
Please, Sign In to add comment