kli*_*ore 11 javascript ecmascript-6
所以,我将一个对象传递给ES6函数,我想将其解构为参数的参数.例如,下面的代码将记录data的道具stuff,但我想它来记录things的道具data的stuff.所以正确的答案会记录下来[1,2,3,4].我知道,根本不会混淆.任何人都知道这是否可行?
const stuff = {
data: {
things: [1,2,3,4]
}
};
const getThings = ({ data }) => {
console.log(data)
};
getThings(stuff);
Run Code Online (Sandbox Code Playgroud)
Ami*_*mit 22
当然,这是如何:
const stuff = {
data: {
things: [1,2,3,4]
}
};
const getThings = ({ data: {things} }) => {
console.log(things)
};
getThings(stuff);Run Code Online (Sandbox Code Playgroud)
As I correctly understood you, the correct answer is:
const getThings = ({ data: { things } }) => {
console.log(things)
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3024 次 |
| 最近记录: |