📦 Destructuring
Destructuring pozwala rozpakowywać listy i mapy do zmiennych.
List destructuring
let [a, b, c] = [1, 2, 3];
print(a, b, c);
let [x, y, z = 100] = [10, 20];
print(z);
Map destructuring
let config = {host: "localhost", port: 8080};
let {host, port, timeout = 5000} = config;
print(host);
print(timeout);
W parametrach funkcji
fn processPoint({x, y}) {
return `Point: ${x}, ${y}`;
}
processPoint({x: 10, y: 20});