JS: Reflect.set

By Xah Lee. Date: . Last updated: .

New in ES2015.

Similar to obj[key] = val.

Add or modify a property. Returns true if success, else false.

receiver todo

var e = {};
Reflect.set ( e , "p", 3 )
console.log(e) // { p: 3 }

Example of failure:

// example of failed attempt to set property
var e = {};
Object.preventExtensions ( e );
var returnValue = Reflect.set ( e , "p", 3 );
console.log(e) // {}
console.log(returnValue) // false

[see JS: Access Property]

Reference

ECMAScript® 2016 Language Specification#sec-reflect.set

back to JS: Reflect

Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog