Scope issue, I thought function statements were always hoisted to the top of the current context. So why is ‘hideNav()’ undefined in the following?
var t;
function showNav(bflag){
clearTimeout(t);
if(bflag===true){
$("#tS2").stop(false,false).animate({
'bottom':'0'
}, 1000);
}else{
t=setTimeout("hideNav()",1000);
}
}
function hideNav(){
$("#tS2").stop(true,false).animate({
'bottom':'-125px'
}, 1000);
}
Change,
to
hideNavis only defined in the current context, but you are passing a string tosetTimeout. That string will be eval’d when the timeout occurs in the context of the global object. Since yourhideNavfunction is not defined in the global object, it will throw an exception.By directly passing a reference to the function to
setTimeout, you don’t have to worry about it.