Where destructuring in ES6 allows you to easily get properties out of an object, this shorthand property syntax allows you to easily push properties in.
let firstName = "Answer"; let lastName = "Question"; let person = {firstName, lastName} console.log(person); // { firstName: ‘Answer‘, lastName: ‘Question‘ } let mascot = "Moose"; let team = {person, mascot}; console.log(team); // { person: { firstName: ‘Answer‘, lastName: ‘Question‘ }, //mascot: ‘Moose‘ }
时间: 2024-10-13 19:40:10