I have
function doSomething(callback) {
if (callback.arguments.length == 1) { // Need help here
// Some logic here
callback(obj1);
}
else {
// Some other logic here
callback(obj1, obj2);
}
}
if (someLogic) {
doSomething(function(arg1) { ... });
}
else {
doSomething(function(arg1, arg2) { ... });
}
How can I check the length of the callback's arguments before calling it?
Use callback.length.
The length property on any function tells you the number of named arguments that function expects.
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