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={};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==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};$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(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.prototype=$jscomp.objectCreate(b.prototype);a.prototype.constructor=a;if($jscomp.setPrototypeOf){var c=$jscomp.setPrototypeOf;c(a,b)}else for(c in b)if("prototype"!=c)if(Object.defineProperties){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=function(a){Polygon.call(this,a,a);this.name="Square"};
$jscomp.inherits(Square,Polygon);$jscomp.global.Object.defineProperties(Square.prototype,{area:{configurable:!0,enumerable:!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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
Works perfectly on cutting edge Espruino builds.
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:
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.