i have two functions, the parent function is __triggerAction, than child function is __triggerNormal which the parent $current is being updated, how to parse the new
$current = $index
from __triggerNormal back to __triggerAction?
_triggerAction = function(el, click, fx) {
var $current, $link;
$link = el.find('.tab-menu').find('li');
$current = 0;
if (click) {
log('Trigger by click');
return $link.click(function() {
return __triggerNormal(this, el, $current, fx);
});
} else {
log('Trigger by hover');
return $link.hover(function() {
return __triggerNormal(this, el, $current, fx);
});
}
};
__triggerNormal = function(thisEl, el, $current, fx) {
var $index;
if (!($(thisEl).hasClass("active"))) {
log('current slide ' + $current);
log($index = $(thisEl).index());
__addRemoveClass(thisEl);
__fxAction(el, fx, $current, $index);
return $current = $index;
}
};
Instead of
do
$currentis not shared between the functions, so inside__triggerNormal,just updates the local variable. You can just write
Btw, the return value of event handlers is only used for determining whether to prevent the default action and stop the propagation or not. It does not seems to be necessary in your case to
return $currentat all.