• Thanks fo the feedback!


    Yes! for (a in global) { console.log(a, "is a", typeof eval(a)) }. I will have a think if it makes sense to use this instead.

    Good point about eval(undefined). Does this actually fail, or is it that accessing a variable that doesn't exist is causing a reference error?

    I meant UART.eval('functionwithnoreturnstatement­()', cb), will try to evaluate the result of the function call on the device, get undefined back, then try to interpret is as a JSON (https://github.com/espruino/EspruinoWebT­ools/blob/13032d0e862d9976ed5eed33b42f07­e93e6c25c3/uart.js#L492). It will fail, be send to the catch, and call the callback with null (https://github.com/espruino/EspruinoWebT­ools/blob/13032d0e862d9976ed5eed33b42f07­e93e6c25c3/uart.js#L496). So we cannot make the difference between a successful call to a real function and a call to something that does not exist or failed to execute properly.

    In other words, in the example above, await proxymiseRobot.toggle() will return null, instead of undefined.

    This try/catch mechanism is great when we got an error and should be kept, but would be nice to have a third case for undefined like:

    if (d.trim() == "undefined") {
    } else {
     // do what is already being done

    but you might be able to make get return a function, but with a valueOf method

    Do you mean something like this?

    var a = function() { return 12;}
    a.prototype.valueOf = function() { return 42;};
    console.log(a)  // would like 42, got function() { return 12;}
    console.log(a()) // would like 12, got 12

    Would be perfect indeed, but does not seem to work for functions.


Avatar for jgrizou @jgrizou started