Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. class User {
  2.  
  3. constructor(name) {
  4. // вызывает сеттер
  5. this.name = name;
  6. }
  7.  
  8. get name() {
  9. return this._name;
  10. }
  11.  
  12. set name(value) {
  13. if (value.length < 4) {
  14. alert("Имя слишком короткое.");
  15. return;
  16. }
  17. this._name = value;
  18. }
  19.  
  20. }
  21.  
  22. let user = new User("Иван");
  23. console.log(user.name); // Иван
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement