When I first began programming with JavaScript, I created my variables and then encapsulated any functionality I needed to reuse into a function. As my tasks got more complicated and as I started learning object-oriented programming in other languages, I began to see the benefits of applying that to JavaScript.

In JavaScript, a function is an object; creating a function creates an object. Function objects can be a little more useful than the object literals we just discussed, though, in that they can be used as a template for new objects.

As scripts get larger, functions become more interrelated. Suddenly, you've got ten functions on a page, six of them calling each other to accomplish one task, and another four working towards something else entirely. For someone taking a first look at this code, it certainly wouldn't be immediately clear which were meant to work together and which weren't. This is where objects come in.