Javascript 在NodeJ中将多个功能参数合并为一个

Javascript 在NodeJ中将多个功能参数合并为一个,javascript,node.js,Javascript,Node.js,是否可以在NodeJ中将多个函数参数组合成一个?例如: var foo = “test1” var bar = “test2” var combined = foo,bar function myFunction(input){ console.log(foo) console.log(bar) } myFunction(combined) //test1 //test2 编辑: 我正在尝试将其用于shelljs exec代理: var shell = require('shellj

是否可以在NodeJ中将多个函数参数组合成一个?例如:

var foo = “test1”
var bar = “test2”

var combined = foo,bar

function myFunction(input){

console.log(foo)
console.log(bar)
}

myFunction(combined)

//test1
//test2
编辑: 我正在尝试将其用于shelljs exec代理:

var shell = require('shelljs-exec-proxy')
var currentSourceLine = "/home/haveagitgat/Desktop/1/1'.mp4"
var currentDestinationLine = "/home/haveagitgat/Desktop/2/1'.mp4"


//Normally called like this 

shell.HandBrakeCLI('-i', currentSourceLine, '-o', currentDestinationLine, '-Z', 'Very Fast 1080p30');

//Would like to call with something like this

var combined = '-i', currentSourceLine, '-o', currentDestinationLine, '-Z', 'Very Fast 1080p30'


shell.HandBrakeCLI(combined);

一个简单的解决方案是使用对象,如:

var foo = "test1"
var bar = "test2"

var combined = {
   foo,
   bar
}

function myFunction(input){

console.log(input.foo)
console.log(input.bar)
}

myFunction(combined)
编辑:已编辑问题的解决方案

var combined = ['-i', currentSourceLine, '-o', currentDestinationLine, '-Z', 'Very Fast 1080p30'] // This is an Array of arguments!
shell.HandBrakeCLI(...combined); // This uses argument destructuring

为什么不把一个物体传进来?您可以使用
{foo,bar}
作为函数的参数,可以同时获取foo和bar。@technogeek1995感谢您的建议,但我在编辑中添加了更多信息,解释了为什么我认为我无法做到这一点。我试图在我的一个项目中使用shelljs exec proxy-我无法访问函数的内部工作,因此我认为我不能使用对象。例如,该函数通常为shell.exec(foo,bar),但我希望能够传入shell.exec(组合),这样我就不必重写所有其他代码。添加多个参数的方式可能取决于要执行的shell代码。我建议在你的问题中添加更多的信息。@HaveAGitGat我已经为你的问题添加了一个解决方案。别忘了@someone,让他们得到通知!谢谢你,我现在就试试!我在手机上试了两次‘@’你,但由于某种原因,它似乎不起作用,一定是临时错误或其他原因。