• Thanks - yes, it looks like there's some issue with Espruino there. It's a strange one as I added it in 2v22 and was pretty sure it was working at that point (but then I wasn't working on getters). I just filed an issue in https://github.com/espruino/Espruino/iss­ues/2517

    I feel like having a getter to handle this is probably overkill though?

    You could have a static propery like GP8403.CH1="CH1"; and so on, and then:

    const channels = { CH0: data_for_ch, CH1: data_for_ch ];
    if (!channels[channel]) throw new Exception("Invalid channel");
    

    I think that's what you were saying? The JS classes are effectively just shorthand for writing out object oriented JS as functions, so if you do want static fields and want to target existing firmwares before I have fixed the issue, you can fix and match - so:

    class GP8403 {
      // ...
    };
    // static fields
    GP8403.CH1="CH1";
    // export
    exports.GP8403 = GP8403;
    

    should all work ok?

About

Avatar for Gordon @Gordon started