I have 2 functions in javascript. The 2nd one uses result of 1st one.Now I have to use both function in one script. Using simple code (calling both functions) not working as 1st one takes more time.. any simple solution. Don't want to change code very much??
            Asked
            
        
        
            Active
            
        
            Viewed 171 times
        
    -3
            
            
        - 
                    3Please post relevant code and what you've actually tried. – Paul Armstrong Jun 20 '13 at 19:41
- 
                    Show us some code so we have a better idea on what you are trying to do and better ways to accomplish that. – BrunoLM Jun 20 '13 at 19:44
2 Answers
1
            
            
        You could implement f1 with a callback
function f1(callback)
{
    /* code */
    var result = "";
    callback(result);
    return result;
}
function f2(resultFromF1)
{
}
And call
f1(f2);
So when f1 finishes, f2 will be executed sending the result of f1 as a parameter.
 
    
    
        BrunoLM
        
- 97,872
- 84
- 296
- 452
0
            This is the simple solution :
var global;
function func1()
{
    //Function1 Code.Process global
    func2();
}
function func2()
{
       //Function2 code
}
Or you could use the callback method as said by Bruno
 
    
    
        Usual Suspect
        
- 601
- 1
- 8
- 19
