The set(target, property, value, receiver) method

The set trap is invoked when we set the value of a property using the assignment operator, or the Reflect.set() method. It takes four parameter-- that is, the target object, the property name, the new property value, and the receiver.

The set trap must return true if the assignment was successful. Otherwise, it will return false.

Here is a code example that demonstrates how to use the set trap:

const proxy = new Proxy({}, { set(target, property, value, receiver) {     target[property] = value;     return true; } }); proxy.name = "Eden";console.log(proxy.name); //Output "Eden"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.