• Below three code fragments just work fine - on uploading the code - up and including [1v75]. The setTimeout() happens and calls fE(). Not so though in [v1V79]. All three are broken: setTimeout() is not happening, does not throw any error, and fE() is just not invoked.

    Fragment 1:

    var log = function() { console.log(arguments); };
    var f1  = function() { log("f1(): "); f2(); };
    var f2  = function() { log("f2(): "); f3(); };
    var f3  = function() { log("f3(): "); setTimeout(fE,100); };
    var fE  = function() { log("fE(): "); };
    f1();
    

    Fragment 2:

    var log = function() { console.log(arguments); };
    var f1  = function() { log("f1(): "); f2(); };
    var f2  = function() { log("f2(): "); f3(); };
    var f3  = function() { log("f3(): "); setTimeout("fE()",100); };
    var fE  = function() { log("fE(): "); };
    f1();
    

    Fragment 3:

    var log = function() { console.log(arguments); };
    var f1  = function() { log("f1(): "); f2(); };
    var f2  = function() { log("f2(): "); f3(); };
    var f3  = function() { log("f3(): "); setTimeout(function(){ fE(); },100); };
    var fE  = function() { log("fE(): "); };
    f1();
    

    The misterious work around below works:

    var log = function() { console.log(arguments); };
    var f1  = function() { log("f1(): "); f2(); };
    var f2  = function() { log("f2(): "); f3(); };
    var f3  = function() { log("f3(): "); setTimeout(fE,100); };
    var fE  = function() { log("fE(): "); };
    // f1();
    var onInit = function() { f1(); }
    onInit();
    

    But the work around works only if he extra function is THE onInit() function. If onInit() is renamed to, for example, abc(), it is not working...

    ???

  • Not sure what's going on - is the code uploading correctly, or do you have something else saved in Espruino? I just ran all 3, on Pico and original boards using the 1v79 release from the website and got:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v79 Copyright 2015 G.Williams
    >echo(0);
    [
      "f1(): "
     ]
    [
      "f2(): "
     ]
    [
      "f3(): "
     ]
    =undefined
    >
    =undefined
    [
      "fE(): "
     ]
    

    Which is exactly what you'd expect?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

setTimeout() broken... not exactly, but if in upload and...

Posted by Avatar for allObjects @allObjects

Actions