Reputation: 2301
This function accepts up to three parameters. I want to be able to pass those parameters on to the callback function so that I am able to check the arguments there in my if statement.
I checked with console log if there are any parameters present in the callback, and there weren't any.
function foobar(x, y, z) {
$("div").fadeOut(300, function() {
if(arguments.length == 1) {
//nothing
} else if(arguments.length == 2) {
$("div").html(x + y).fadeIn(300);
} else if(arguments.length == 3) {
$("div").html(x + y + z).fadeIn(300);
}
});
}
Upvotes: 0
Views: 420
Reputation: 152266
arguments
refers to the nearest function, so here it is a fadeOut
callback. Assign foobar
function's arguments to the new variable:
function foobar(x, y, z) {
var foobarArguments = arguments;
$("div").fadeOut(300, function() {
if(foobarArguments.length == 1) {
//nothing
} else if(foobarArguments.length == 2) {
$("div").html(x + y).fadeIn(300);
} else if(foobarArguments.length == 3) {
$("div").html(x + y + z).fadeIn(300);
}
});
}
Upvotes: 1