Mark McCann

Object-Oriented JavaScript Template

A simple pattern for writing applications in JavaScript based on object–oriented principles.

Coming from more strictly-typed languages, developers new to JavaScript may find its implementation of object-oriented principles, a little wonky. If this is you, the template below is an example of how I like to write and organize my applications. I hope it can help you better understand how to accomplish certain object-oriented tasks in the language.

The Class

By wrapping your class in a self-invoking function you can create "private" variables and functions available to your object and nothing else. Learn more about the modular pattern here.