Reputation: 539
How to call a function with variable number of arguments from JavaScript, defined eg. like this?
setIntValues(int... values)
(the example is from android.animation.ObjectAnimator
object)
Upvotes: 0
Views: 55
Reputation: 2354
if you're using javascript:
var arr = [1,2,3];
setIntValues.apply(undefined, arr);
if you're using typescript:
const arr = [1,2,3];
setIntValues(...arr);
Upvotes: 0
Reputation: 539
You pass the arguments as an array:
obj.setIntValues([0,5]);
For defining a type, in overloaded functions you can use:
var arr = Array.create("int",2);
arr[0] = 0;
arr[1] = 5;
obj.setIntValues(arr);
Upvotes: 1