使用解构仅提取 person 的状态。
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({ @(18) }) {
const message = 'I live in ' + state + '.';
}
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({ address: { state } }) {
const message = 'I live in ' + state + '.';
}
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({ address:{state} }) {
const message = 'I live in ' + state + '.';
}
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({address:{state}}) {
const message = 'I live in ' + state + '.';
}
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({address:{ state }}) {
const message = 'I live in ' + state + '.';
}
const person = {
name: 'Jesse',
age: 30,
address: {
city: 'Houston',
state: 'Texas',
country: 'USA'
}
}
displayMessage(person)
function displayMessage({address: {state}}) {
const message = 'I live in ' + state + '.';
}