Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript protect object with proxy

// 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;
  },
});
 
PREVIOUS NEXT
Tagged: #javascript #protect #object #proxy
ADD COMMENT
Topic
Name
8+5 =