Simple Class-based Function Pattern for JavaScript

Some sample code and an overview of a neat, simple pattern Brad and I used when we wrote the HTML Player over at Vimeo:

When your JavaScript code gets loaded tens of thousands of times a minute, every little byte counts. Therefore, right at the outset we wanted to come up with a simple pattern around which we could structure our code that would allow us great flexibility (we’d be developing 3 players, afterall: Desktop, Mobile, and Touch) but would also lend itself to good compression before deployment (in our case via Google’s Closure Compiler).

Now, there are many, many, many things that we did to bring our video player source code to its svelte ~25k, but one of the techniques was to be extremely precise in scope for our class methods. Above you can see some stubbed-out code that illustrates the three different types of class methods we used: Private, Privileged, and Public.

Click through to see the sample code as well as explanations for the three method types.

  1. reusablebits posted this
blog comments powered by Disqus