const profileUpdate =(profileData)=> {这有效地破坏了发送到函数中的对象。这也可以就地完成:
const {name,age,nationality,location} = profileData;
//用这些变量做点什么
}
const profileUpdate =({name,age,nationality,location})=> {这将删除一些额外的行,使我们的代码看起来整洁。这具有额外的好处,即不必操纵函数中的整个对象;只有所需的字段才会复制到函数内部。
/ *用这些字段做某事* /
}
half
的参数内使用解构赋值,仅在函数内发送max
和min
。 stats
应该是一个object
。
testString: 'assert(typeof stats === "object", "stats
should be an object
.");'
- text: half(stats)
应为28.015
testString: 'assert(half(stats) === 28.015, "half(stats)
should be 28.015
");'
- text: 使用了解构。
testString: 'getUserInput => assert(getUserInput("index").match(/\(\s*\{\s*\w+\s*,\s*\w+\s*\}\s*\)/g), "Destructuring was used.");'
```