• If you're using objects I'd say bar3 is probably best - but if you don't need any state then just export functions rather than a whole object.

    If you do:

    function Foo(){
      this.bar = bar;
      };
    

    then even once initialised, Espruino will still contain this.bar = bar;, which would be wasting some memory.

    The important thing to remember is that Espruino actually executes the module code at the time it is uploaded, so:

    function Foo() {
    }
    
    Foo.prototype.bar = function() {
    };
    

    Is executed, and you end up with effectively:

    var Foo = {
      prototype : {
       bar : function() {}
      }
    };
    

    So it doesn't actually matter if you manage to take few bytes off the minified module. What matters is the amount of memory that's used (process.memory().usage) after the module has been uploaded - and for that, you want the minimum amount of 'boilerplate' code inside functions.

About

Avatar for Gordon @Gordon started