Every time I want a function run with callback, I have to change my parameter from (par1,par2)
to (args)
. Is there any way to keep my parameter name?
Here is my code now:
function runwithcallback(callback, ...args) {
callback(args);
}
function Boo(args){
let par1 = args[0];
let par2 = args[1];
}
function Foo(args){
let par1 = args[0];
let par2 = args[1];
let par3 = args[2];
}
//normal call
Boo(["1","2"]);
Foo(["1","2","3"]);
//call with callback
runwithcallback(Boo,"1","2");
runwithcallback(Foo,"1","2","3");
And what I want:
function runwithcallback(callback, ...args) {
callback(args);
}
function Boo(par1, par2){
}
function Foo(par1, par2, par3){
}
//normal call
Boo("1","2");
Foo("1","2","3");
//call with callback
runwithcallback(Boo,"1","2");
runwithcallback(Foo,"1","2","3");