[英]Returning object values in an object?
I want to access two parameters to a function and turn them into a single object to pass to another function.我想访问 function 的两个参数并将它们转换为单个 object 以传递给另一个 function。 I know about Object.values
, but I don't want to call otherFn
with an array, I want an object.我知道Object.values
,但我不想用数组调用otherFn
,我想要一个 object。 What's the best way to approach this?解决这个问题的最佳方法是什么?
const exampleFn = (x, y) => {
otherFn(?);
}
Create an object with the function's arguments:使用函数的 arguments 创建一个 object:
const exampleFn = (x, y) => {
otherFn({x,y});
}
Take the arguments from the first function.从第一个 function 中取出 arguments。
Put them into an object.将它们放入 object 中。
Pass object to second function.将 object 传递给第二个 function。
const exampleFn = (x, y) => {
const args = {x: x, y: y}
otherFn(args)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.