• Thanks - that's interesting... Unlike normal functions, Arrow functions store the value of this when they are defined.

    In that code, it looks like they're expecting this to be something else though. Maybe ES6 defines some magic case where if you do new ArrowFunction, this is no longer what it's expected to be what it is in every other case.

    Actually MDN has this to say: https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Functions/Arro­w_functions#Use_of_the_new_operator

    Arrow functions cannot be used as constructors and will throw an error when used with new.

    So it looks like the code is invalid. And if you try and run even a small snippert in Node.js, it fails:

    var _b, b = () => {_b = this;};
    new b()
    // Uncaught TypeError: b is not a constructor
    

    Where did the code come from? If anything Espruino's failing here appears to be not producing an error when new ArrowFn is used.

About

Avatar for Gordon @Gordon started