Desestruturación objetos

by Fabian Allel

JavaScript

//desestruturar objeto

var objeto = { nombre: "fabian", numeros: [3,5,7]};


var { nombre :x} = objeto;

console.log(x);

var { numeros :[,,y]} = objeto;

console.log(y);

var foo = function({uri, method: method='GET', contentType: ctype='application/json'}) {
    // En este punto las variables uri, method y ctype ya existen gracias a la desestructuración
    console.log(uri, method, ctype);
}

foo({uri:"caca", method: "Post"});