// stable code version
Modules.addCached("a",( function(){
var _a,
a = function(){_a = this;},
pa = a.prototype;
pa.sqrt = (a) => {return _a._sqrt(a);};
pa._sqrt = (a) => {return Math.sqrt(a);};
exports.create = function(){ return new a();};
}));
a = require('a').create();
console.log(a.sqrt(3));
// es6 code version
Modules.addCached("b",(()=>{
var _b,
b = () => {_b = this;},
pb = b.prototype;
pb.sqrt = (a) => {return _b._sqrt(a);};
pb._sqrt = (a) => {return Math.sqrt(a);};
exports.create = () => { return new b();};
}));
b = require('b').create();
console.log(b.sqrt(3));
output:
>1.73205080756
Uncaught Error: Function "_sqrt" not found!
at line 1 col 4
_b._sqrt(a);
^
in function "sqrt" called from line 26 col 21
console.log(b.sqrt(3));
^
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.
Is there something missing in the es6 version to make it work?
board information:
code:
output: