You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • If you're writing a module?

    Generally I'd say:

    • Putting stuff straight into the actual object saves a (very small) amount of RAM, and is a bit faster.
    • But if you're going to have more than one object, you're best to use prototype to reduce duplication.

    Also doing:

    function x() {
      return {
       myproperties: {},
       method1: function() {},
       method2:function(){}
      };
    }
    

    Isn't great, as you've got a copy of the code in the function itself, plus a copy in the instantiated object -> prototypes can be better there too.

    Just to add, when minifying, anything that's exposed to the outside world (like stuff in the prototype) can't have its name changed, so uses up more memory.

About

Avatar for Gordon @Gordon started