• Is there something missing in the es6 version to make it work?

    board information:

    >process.env
    ={
      VERSION: "2v08.117",
      GIT_COMMIT: "8af54959a",
      BOARD: "LINUX",
      FLASH: 262144, SPIFLASH: 262144, STORAGE: 262144, RAM: 0,
      SERIAL: "00000000-addeadde-addeadde",
      CONSOLE: "Telnet",
      MODULES: "Flash,Storage,hea" ... "crypto,tensorflow",
      EXPTR: 22978688 }
    

    code:

    // 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));
                        ^
    
About

Avatar for MaBe @MaBe started