How can I write variable arity functions in Unityscript?

Is it possible to write variable arity functions in Javascript/Unityscript? I know with C#, I can use "params object[]" as the last argument to a function to allow it to take an arbitrary number of parameters, but is there a way to achieve a similar effect in Unityscript (without having to pack arguments into an Object array)?

You can overload functions in javascript, so that you can define versions of the same function name which accepts 1, 2, 3 or more parameters (but not an indefinite number).

Read more about function overloading in Unity (C# and JS) here

Of course there's nothing stopping you from passing an object array to your Unityscript function either (just as you suggest is possible in c#).

In general though, passing an assortment of unrelated object types as an object array instead of having explicitly typed parameters sounds like it may be a case of bad design. And if your assortment of object types are related (i.e. they're all the same type, or they're all descendents of some common type other than 'Object'), then you should probably pass an array whose type is their nearest common parent, rather than Object.

Not sure if it works in Unity (and I don't have access to Unity right this moment to test this), but Javascript itself defines a .arguments property for each function that you can use to inspect all parameters passed to a function, whether those parameters are formally declared or not.

This example works under FireFox, hopefully it can be translated to what you specifically need in Unity:

<script type="text/javascript" language="javascript">
function popupParams() {
  for (i = 0; i<popupParams.arguments.length; i++)
*<script type="text/javascript" language="javascript">*
 *popupParams("1st", "2nd", "3rd", "4th");*