0

I have nested function and i want to return from outer function by firing _.after.

The function that's targeted with _.after doesn't return the most outer

function myFunction(){
    var finished = _.after(1, doReturn);
    var state = false;
    function asynclogic(){
         state = true;
         finished();
    }
    function doReturn(){
          return state;  //<-- make a return for myFunction, not just for doReturn
    }


}

EDIT: I want to make a return for a myFunction (outer) using doReturn (inner function) using _.after from underscore

Jask
  • 660
  • 10
  • 23
  • Can you please be more clear about what you want to achieve? – void Feb 21 '15 at 20:35
  • @void i made edit, it might be clearer now – Jask Feb 21 '15 at 20:40
  • 1
    Take a look at promises (in es6 or from various libraries/frameworks) .myFunction could return a promise that is resolved in doReturn. – Gruff Bunny Feb 22 '15 at 12:55
  • `_.after` won't solve the fundamental issue that your code is asynchronous and therefore cannot return a value immediately. As Gruff Bunny noted, you might want to look into promises. – Qantas 94 Heavy Feb 23 '15 at 12:35
  • possible duplicate of [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – Qantas 94 Heavy Feb 23 '15 at 12:35

0 Answers0