Currently I’ve set it up like this,
var elements = $('#one, $two, #three, #four, #six');
var _temp = 0;
elements.hide(0, function(){
/* by default, the callback will be performed to
every single element in stack */
_temp++; // increment temporary cache
// perform actual callback only on last in list
if (_temp == elements.length) {
// do stuff
}
});
but it feels wrong, because if I’d want to do the same for another callback 241 lines below, I’d have to reset _temp and well, global variables are just messy.
How could I simplify this?
One possible way is to use a closure:
If you want to use this pattern more often you could create a function which returns a callback.
Also note that
.hide()has a duration as first argument.