I have the following function:
function foo(f, k) {
if (f.length > 2) {
// how do I access the third element of f?
// it can be a function retry() or undefined.
// var retry = f.arguments[2]; ??
// retry();
// console.log(f.arguments) returns undefined
} else {
k();
}
}
var retry = function() { console.log("hi"); };
foo(function(x, y) { console.log(x+y); },
function() { console.log("hello"); });
foo(function(x, y, retry) { console.log("retry present"); },
function() { console.log("hello"); });
I need to call that third argument if its passed in. I may have 2
or 3
arguments being passed to f
. How do I access that third argument if it's present?