The Reflect.set(object, property, value, this) method

The Reflect.set() method is used to set the value of an object's property. The first argument is the object, the second argument is the property name, and the third argument is the property value. If the property is an accessor property, then we can provide a fourth argument, which will be the value of this inside the set function.

The Reflect.set() method returns true if the property value was set successfully. Otherwise, it returns false.

Here is a code example that demonstrates how to use the Reflect.set() method:

var obj1 = { __name__: "Eden" }; Reflect.defineProperty(obj1, "name", {   set: function(newName){     this.__name__ = newName;   },   get: function(){     return this.__name__;  } ...

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.