Answers for "javascript middleware getter and setter"

0

javascript middleware getter and setter

// Use a Proxy object with getter/setter traps instead
const obj = {};

const proxObj = new Proxy(obj, {
  get(obj, prop) {
    console.log(`Getting ${prop} from `, obj));
    return obj[prop];
  },
  set(obj, prop, newValue) {
	console.log(`Setting ${prop} with value ${newValue} on `, obj));
    return obj[prop] = newValue;
  },
});
Posted by: Guest on November-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language