如果我有以下ES6方法:
function myClothes([first, second, third]) {
return {
first: first,
second: second,
third: third
}
}
如何在控制台窗口中打印出“运动鞋裤子衬衫”?我已经尝试了以下方法,但是仍然缺少解决方案:
console.log(myClothes({
['first']:'sneakers',
['second']:'pants',
['third']:'shirt'
}));
我究竟做错了什么?
非常感谢!
首先,更改您的功能以使用对象分解。然后console.log
在函数内部使用一个简单的语句:
function myClothes({first, second, third}) {
console.log([first, second, third].join(" "));
return {
first: first,
second: second,
third: third
}
}
console.log(myClothes({
['first']:'sneakers',
['second']:'pants',
['third']:'shirt'
}));
.as-console-wrapper { max-height: 100% !important; top: auto; }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句