Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // instantiate
- var a = {}
- var b = {}
- // set values
- a.val = 10
- // check values
- console.log("A.val is:", a.val) //=> 10
- console.log("B.val is:", b.val) //=> undefined
- // bind values
- Object.defineProperties(a, {
- val: {
- configurable: true, // can be changed or deleted
- enumerable: true, // can be interated over
- get: ()=> this.val,
- set: (value)=> {
- this.val = value
- b.val = value
- }
- }
- })
- // reset value
- a.val = 20
- // check values
- console.log("A.val is:", a.val) // => 20
- console.log("B.val is:", b.val) // => 20
Add Comment
Please, Sign In to add comment