var voxel = {x: 3.6, y: 7.4, z: 6.54};Aquí está la misma declaración de asignación con la sintaxis de desestructuración ES6:
var x = voxel.x; // x = 3.6
var y = voxel.y; // y = 7.4
var z = voxel.z; // z = 6.54
const {x, y, z} = voxel; // x = 3.6, y = 7.4, z = 6.54Si, por el contrario, desea almacenar los valores de
voxel.x
en a
, voxel.y
en b
, y voxel.z
en c
, también tiene esa libertad. const {x: a, y: b, z: c} = vóxel // a = 3.6, b = 7.4, c = 6.54Puede leerlo como "obtener el campo
x
y copiar el valor en a
", y así sucesivamente. AVG_TEMPERATURES
, y asigne un valor con la clave tomorrow
a tempOfTomorrow
en línea. getTempOfTmrw(AVG_TEMPERATURES)
debe ser 79
testString: 'assert(getTempOfTmrw(AVG_TEMPERATURES) === 79, "getTempOfTmrw(AVG_TEMPERATURES)
should be 79
");'
- text: Se utilizó desestructuración con reasignación.
testString: 'getUserInput => assert(getUserInput("index").match(/\{\s*tomorrow\s*:\s*tempOfTomorrow\s*}\s*=\s*avgTemperatures/g),"destructuring with reassignment was used");'
```