A few days ago I did some code refactoring:
|File||Bytes before||Bytes after|
The direct assignment module pattern is simple to understand, but the code ended up with ‘this.’ and the name of the object everywhere. While the object name was short, repeating it many times bloated the code size.
So why did the refactored source file end up bigger? Well, I use JSLint, so I end up with a single huge var declaration for all of the object’s members. All the methods end up indented one more level when using the new module pattern. And of course, the indentation is done using spaces. For a less misleading impression, I compared the code size minus all whitespace. Even with the new pattern’s requirement to re-list all public methods, the non-whitespace parts of the code ended up around 2KB smaller, thanks to removing all the ‘this’s and object names.