Guest User

Untitled

a guest
May 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // instantiate
  2. var a = {}
  3. var b = {}
  4.  
  5. // set values
  6. a.val = 10
  7.  
  8. // check values
  9. console.log("A.val is:", a.val) //=> 10
  10. console.log("B.val is:", b.val) //=> undefined
  11.  
  12. // bind values
  13. Object.defineProperties(a, {
  14. val: {
  15. configurable: true, // can be changed or deleted
  16. enumerable: true, // can be interated over
  17. get: ()=> this.val,
  18. set: (value)=> {
  19. this.val = value
  20. b.val = value
  21. }
  22. }
  23. })
  24.  
  25. // reset value
  26. a.val = 20
  27.  
  28. // check values
  29. console.log("A.val is:", a.val) // => 20
  30. console.log("B.val is:", b.val) // => 20
Add Comment
Please, Sign In to add comment