Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You are just asking for race condition issues with that type of "solution."


Are you referring to a case like this?

    {
      f();
      var a = 3;
      function f() {
        console.log(a);
      }
    }
That will print "undefined" because the entire function f() is hoisted and callable in the first line, but the variable a has not yet been assigned the value. That's not a race condition (those are related to timing in concurrent systems) but is certainly the sort of counter-intuitive visibility that makes me prefer to use function expressions most of the time.


You can still pass in callbacks to them. So if I got the parent's intent right, you've got:

  function bunchOfAsyncThings(callback) {
    var function1, function2;
  
    function1 = function (callback) {
      // do stuff here, then do callback
      function2(callback);
    };
    
    function 2 = function (callback) {
      // done with everything
      callback();
    };
   
    function1(callback);
  }
(Edit: formatting)


how, exactly, is that going to cause race conditions?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: