javascript middleware getter and setter

Solutions on MaxInterview for javascript middleware getter and setter by the best coders in the world

showing results for - "javascript middleware getter and setter"
Julia
19 Jun 2016
1// Use a Proxy object with getter/setter traps instead
2const obj = {};
3
4const proxObj = new Proxy(obj, {
5  get(obj, prop) {
6    console.log(`Getting ${prop} from `, obj));
7    return obj[prop];
8  },
9  set(obj, prop, newValue) {
10	console.log(`Setting ${prop} with value ${newValue} on `, obj));
11    return obj[prop] = newValue;
12  },
13});