我想直接在函数的参数列表上使用es6从对象获取这些属性,但我不知道该怎么做:
function methodA(person){
var driverName = person.name,
age = person.age,
company = person.job.company;
...
}
有没有朝这个方向发展的提示?
答案 0 :(得分:0)
function methodA(person) {
var { name: driverName, age, job: { company } } = person;
console.log(driverName, age, company);
}
methodA({ name: 'Grace', age: 49, job: { company: 'Infinity' } })