-1

Here is what I am trying to do. Not successful and gives out error. Is it possible to delay the return value, and chain functions such that 2nd one delays the return value?

 a().b() 

function a( )
{
    var self=this;

      setTimeout( function(){ return self },2000);

      return null; //<<<<< this causes problem
}

function b()
{
    trace("hello");
}
Vishwas
  • 1,533
  • 2
  • 19
  • 40

1 Answers1

2

You can do this sort of thing with Promises and (optionally) async/await.

Something like:

function a() {
  return new Promise((resolve) => {
    setTimeout(() => resolve('the return value'), 2000);
  })
}

function b(value) {
  console.log(`from b: ${value}`);
}

a().then(b);
ray
  • 26,557
  • 5
  • 28
  • 27