This is honestly not very advisable. Not only is the code itself rather unhygienic to look at, but you'll lose type information for the extra parameters. Consider, for example, if c
and d
were a bool
and number
, respectively:
var c = true,
d = 3;
var combined = c + ',' + d; // "true,3"
combined.split(','); // ["true", "3"]
Notice that you now have two strings ("true"
, and "3"
), rather than your initial values.
There are other issues as well. For example, if either c
or d
is a string with commas in it, you'll end up with unexpected results on the other side:
var c = 'hello,world',
d = 'foo,bar';
var combined = c + ',' + d; // "hello,world,foo,bar"
combined.split(','); // ["hello", "world", "foo", "bar"]
At this point, it's impossible to tell which "parts" were originally from c
vs. from d
. So now you have to introduce some escaping for commas... yuck.
The ideal solution for this would be to simply change your strict 4-parameter requirement. If this isn't possible, however, I would instead recommend passing extra variables in an array:
function myFunction(a, b, c, d) {
//Lots of code then
GeneralFunction('id1', 'id2', a, b, [c, d]);
}
With this approach, you'll have no loss of type info, and it'll be easier to retrieve the values on the other side.