Just to add to this, if you're describing an extern for an external JavaScript library (or Python, Lua, or any target language that supports the rest parameter, e.g. ...rest
), there is a specific Haxe type, haxe.extern.Rest
, to express this.
Here's an example showing that the JavaScript Math.max
function handles varargs: http://try.haxe.org/#4607C
class Test {
static function main() {
trace("JS Math.max takes varargs:");
trace(MyMath.max(1,2,3,4)); // 4
trace(MyMath.max(5,6)); // 6
}
}
@:native("Math")
extern class MyMath {
static function max(a:Float,
b:Float,
rest:haxe.extern.Rest<Float>):Float;
}
Note that the Haxe standard library does not define Math.max
with Rest
, as its goal is cross-platform compatibility.