Baseline Widely available
El método estático Reflect.set()
funciona igual que asignar una propiedad en un objeto.
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.
El valor de la propiedad.
El valor de this
para usar en la llamada a target
si se encuentra un setter.
Un Boolean
indicando si se pudo o no asignar la propiedad.
Un TypeError
, si target
no es un Object
.
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.
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 Compatibilidad con navegadores Ver también
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4