Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function re(instance, name, val){
- let _value = val;
- Object.defineProperty(instance, name, {
- get: () => {
- console.log('getter called');
- return _value;
- },
- set: (v) => {
- console.log('setter called');
- return _value = v;
- },
- configurable: true
- });
- return val;
- }
- class A {
- prop = re(this, 'prop', 456)
- }
- const a = new A()
- console.log(a.prop);
- a.prop = 123;
- console.log(a.prop);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement