nikolayneykov

Untitled

May 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Cat = (function () {
  2.   let _age = 0
  3.  
  4.   return function (name, age) {
  5.     this.name = name
  6.     Object.defineProperty(this, 'age', {
  7.       configurable: false,
  8.       get () {
  9.         return _age
  10.       },
  11.       set () {
  12.         _age = age
  13.       }
  14.     })
  15.   }
  16. })()
  17.  
  18. let myCat = new Cat('Ivan', 10)
  19. console.log(myCat)
  20. console.log(myCat.name)
  21.  
  22. myCat.age = 5
  23. console.log(myCat.age)
Advertisement
Add Comment
Please, Sign In to add comment