-3

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??

niksya
  • 291
  • 2
  • 11

2 Answers2

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