JavaScript is relatively weak when it comes to reflection and metaprogramming. Let us see what you can and cannot do. This post uses some of the standard methods of ECMAScript 5 (ES5).
Update 2011-06-25: “Prototypes as classes” is an improved version of this blog post.
This blog post explains JavaScript’s prototypal inheritance in a simple way. As it turns out, if we initially leave out constructors, then it is easy to understand. Thus, we first look at the fictional programming language ProtoScript which is JavaScript minus constructors, explain it, and then move on to constructors. As a result, you should have a solid understanding of prototypal inheritance and won’t be confused, any more, by all the JavaScript tricks out there.
Each of the following eight books has greatly influenced how I think about software development. Note that this list is not exhaustive, there are obviously other important books out there, many of whom I have not read (yet).
ECMAScript is a language standard that is implemented as JavaScript in most web browsers (it’s called JScript in MS Internet Explorer). Here are two good links to get up to date on the latest version, ECMAScript 5: