Reflect.set()
El método estático Reflect
.set()
funciona igual que asignar una propiedad en un objeto.
Sintaxis
Reflect.set(target, propertyKey, value[, receiver])
Parámetros
target
- El objeto en el cual se va a asignar una propiedad.
propertyKey
- El nombre de la propiedad a asignar.
- value
- El valor de la propiedad.
- receiver
- El valor de
this
para usar en la llamada atarget
si se encuentra un setter.
Valor de retorno
Un Boolean
indicando si se pudo o no asignar la propiedad.
Excepciones
Descripción
El método Reflect.set
permite asignar una propiedad a un objeto. It does property assignment and is like the property accessor syntax as a function.
Ejemplos
Uso de Reflect.set()
// Objeto
var obj = {};
Reflect.set(obj, 'prop', 'value'); // true
obj.prop; // "value"
// Arreglo
var arr = ['duck', 'duck', 'duck'];
Reflect.set(arr, 2, 'goose'); // true
arr[2]; // "goose"
// Puede truncar un arreglo.
Reflect.set(arr, 'length', 1); // true
arr; // ["duck"];
// Con solo un argumento, propertyKey y value son "undefined".
var obj = {};
Reflect.set(obj); // true
Reflect.getOwnPropertyDescriptor(obj, 'undefined');
// { value: undefined, writable: true, enumerable: true, configurable: true }
Especificaciones
Especificación | Estado | Comentarios |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) La definición de 'Reflect.set' en esta especificación. |
Standard | Initial definition. |
ECMAScript (ECMA-262) La definición de 'Reflect.set' en esta especificación. |
Living Standard |
Compatibilidad con navegadores
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Característica | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Soporte básico | 49 | (Yes) | 42 (42) | Sin soporte | Sin soporte | 10 |
Característica | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Soporte básico | Sin soporte | 49 | (Yes) | 42.0 (42) | Sin soporte | Sin soporte | 10 |