• I'm not sure I understand? Are you running with a minifier turned on? The code you posted below has no mention of setPrototypeOf or $jscomp.global.Object so I presume they are being added by something.

    Uploading the code in your attached file from the main IDE window:

    class Polygon {
      // ..and an (optional) custom class constructor. If one is
      // not supplied, a default constructor is used instead:
      // constructor() { }
      constructor(height, width) {
        this.name = 'Polygon';
        this.height = height;
        this.width = width;
      }
    }
    
    
    
    
    class Square extends Polygon {
      constructor(length) {
        // Here, it calls the parent class' constructor with lengths
        // provided for the Polygon's width and height
        super(length, length);
        // Note: In derived classes, super() must be called before you
        // can use 'this'. Leaving this out will cause a reference error.
        this.name = 'Square';
      }
    
      get area() {
        return this.height * this.width;
      }
    }
    
    
    var pol = new Polygon( 4, 3 );
    

    works perfectly for me on a recent build of Espruino.

  • Wed 2018.09.26

    I'm surprised and disappointed @Gordon that you missed that one. In your code, instance is of base class and not the derived class. It does however show that syntax checking is working. I left in the commented out instantiation lines that followed to show the difference between the two, valid syntax vs run-time, without the need of submitting two files. Was it necessary to add the obvious comment to un-comment the subsequent lines?

    re: 'The code you posted below has no mention of setPrototypeOf'

    Yes, agreed, and as I mentioned that 'never specified an 'inherits' function' also, so that puzzled me too.

    Per your suggestion, when I checked, I had 'Closure Simple Optimizations' turned on, so your presumption is proved. But, that brings up another issue, does this mean the minification process is bad?

    I turned off minification and code passes fine, but fails when turned on. And even more puzzling, when I pass the source through

    https://closure-compiler.appspot.com

    // ==ClosureCompiler==
    // @output_file_name default.js
    // @compilation_level SIMPLE_OPTIMIZATIONS
    // @formatting pretty_print
    // ==/ClosureCompiler==

    that source compiles with:

    Compilation was a success!

    Sending that code, default.js, to the device results in the same error as in #1. How does one troubleshoot that type of error? If I understand this correctly, converting the minified code to byte code is where the issue lies.


    1 Attachment

About

Avatar for Robin @Robin started