I don't follow the overall context of what you're trying to do well enough to know if this is the best option or not, but you can just use code to look at the index
and then decide what to do next.
That can be done with if/else
or with a switch
statement or with a function table.
// if/else
$('#my-container-div').on('onAlbumLoad', function(event, index) {
if (index === 0) {
func1();
} else if (index === 1) {
func2();
}
});
// switch
$('#my-container-div').on('onAlbumLoad', function(event, index) {
switch(index) {
case 0:
func1();
break;
case 1:
func3();
break;
}
});
// function table
var fTable = [func1, func2, func3, func4];
$('#my-container-div').on('onAlbumLoad', function(event, index) {
if (index < fTable.length) {
fTable[index]();
}
});
Any of these would work.
If the number of indexes to compare is two or less, I would use the if/else.
If the number of indexes is more than two and you're checking for a contiguous set of indexes, I'd use the function table because it's more easily extensible without write new code (you just add a new function to the array).
If the indexes you are checking for are more than two and not contiguous, I'd probably use the switch statement.