Question

$(document).ready(function (){
    var x = false;
    $('#board_code').keyup(function(e) {
        if(x)
            callFunc();
    })  
})

function callFunc(){
    if(expression==true)
        x=true;
    else
       x=false;
}

I know i can just put the def of callFunc inside $(document).ready function, but what is the other way so that i wouldnt use global variable

UPDATE: i forgot to put the if(x), check it again. This is for brace matching in my web-based ide project ^^

Was it helpful?

Solution

$(document).ready(function (){
    var x = false;
    $('#board_code').keyup(function(e) {
        x = callFunc();
    })  
})

function callFunc(){
  return expresion ? true : false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top