Say I have some functions stored in an array of objects, each takes a variable amount of arguments:
var ops = [
{
id: "plus",
op: function(a, b) {
return a + b;
}
},
{
id: "inverse",
op: function(a) {
return -a;
}
}
];
How would I determine the number of arguments the function takes from outside the function (Without specifying it as an additional property) e.g.
for (var i = 0; i < ops.length; i++) {
var op = ops[i].op;
var args = ? // Determine number of arguments op takes here
}
Is this even possible? If so how?
Yes, it's possible. Use function.length
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With