Javascript is not generally considered a very object oriented language. It allows
a lot of flexibility in approaches. The following notes detail how to create an
object in javascript utilizing constructor functions.
We create one object, then add a function to its prototype chain to avoid
having it copied many times, then we subclass it and detail how to set up the
prototype chain.
Another common feature leveraged with classes is privacy of variables and functions.
The less we expose in our classes and APIs the less coupling we get between
modules.
use this keyword for public fields
use var to instantiate things only available within this closure.
use this.methodName to define a privileged function, a public function that
can access private variables. Similar to getters.
Alternatively, it is common practice to prefix private variables with _. But you
wont have any guarantees that users of your software will respect not to use them.
You could also explicitly return the object returned by the constructor but
it is not encouraged javascript style. The following produces the same object.