• I'm surprised and disappointed @Gordon that you missed that one.

    You gave me code that you tell me isn't working, and I ran it and it works. As it happens on the first line I said "Are you running with a minifier turned on?" which is exactly what the issue is.

    You commonly upload huge files with massive areas of commented code, so I just assumed it was much the same. I'm trying to help you out here - it's not my job to try and decode the mangled bits of code you post up.

    But just to be clear:

    var sq = new Square( 4 );
    

    Works perfectly on cutting edge Espruino builds.

    var res = sq.area();
    

    Doesn't work, because as I have explained before in answer to one of your other questions, you're using a getter. In that case sq.area is good enough to access the value.

    If you get errors running code, can you please just run it on the JS interpreter in your browser first to make sure you're actually writing valid JS?

    But in this case, your errors seem to be because the Closure minifier has converted your code into the following:

    var $jscomp=$jscomp||{};$jscomp.scope={};$js­comp.getGlobal=function(a){return"undefi­ned"!=typeof window&&window===a?a:"undefined"!=typeof­ global&&null!=global?global:a};$jscomp.g­lobal=$jscomp.getGlobal(this);$jscomp.AS­SUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP­=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jsc­omp.objectCreate=$jscomp.ASSUME_ES5||"fu­nction"==typeof Object.create?Object.create:function(a){­var b=function(){};b.prototype=a;return new b};
    $jscomp.underscoreProtoCanBeSet=function­(){var a={a:!0},b={};try{return b.__proto__=a,b.a}catch(c){}return!1};$j­scomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototyp­eOf:$jscomp.underscoreProtoCanBeSet()?fu­nction(a,b){a.__proto__=b;if(a.__proto__­!==b)throw new TypeError(a+" is not extensible");return a}:null;
    $jscomp.inherits=function(a,b){a.prototy­pe=$jscomp.objectCreate(b.prototype);a.p­rototype.constructor=a;if($jscomp.setPro­totypeOf){var c=$jscomp.setPrototypeOf;c(a,b)}else for(c in b)if("prototype"!=c)if(Object.defineProp­erties){var d=Object.getOwnPropertyDescriptor(b,c);d­&&Object.defineProperty(a,c,d)}else a[c]=b[c];a.superClass_=b.prototype};var­ Polygon=function(a,b){this.name="Polygon­";this.height=a;this.width=b},Square=fun­ction(a){Polygon.call(this,a,a);this.nam­e="Square"};
    $jscomp.inherits(Square,Polygon);$jscomp­.global.Object.defineProperties(Square.p­rototype,{area:{configurable:!0,enumerab­le:!0,get:function(){return this.height*this.width}}});var pol=new Polygon(4,3),sq=new Square(4);
    

    Which obviously doesn't resemble your original classes much. We can't easily set the compiler up such that it uses some ES6 features but not others, so it tries to convert your ES6 code to ES5.

    As it happens this code actually hit what looks like a bug in Object.setPrototypeOf which I have now fixed, so your code should actually upload correctly. However it looks like if you're planning on using Classes inside modules then for now you're best off with whitespace-only optimisations.

About

Avatar for Gordon @Gordon started