1、变量申明,展开运算符
let defaults = { food: ‘spicy‘, price: ‘20‘, ambiance: ‘noisy‘ } let search = {...defaults, food: ‘rich‘} console.log(search)
{ food: ‘rich‘, price: ‘20‘, ambiance: ‘noisy‘ }
let defaults = { food: ‘spicy‘, price: ‘20‘, ambiance: ‘noisy‘ } let search = {food: ‘rich‘, ...defaults} console.log(search)
{ food: ‘spicy‘, price: ‘20‘, ambiance: ‘noisy‘ }
使用展开运算符的时候,注意顺序
原文:https://www.cnblogs.com/zhaobao1830/p/11298748.html