Secrets of the JavaScript Ninja: Chapter 6 Review

Object-Orientation with Prototypes

This chapter goes into object prototypes and how they can be used for inheritance and sub-classing. It also includes a sample method that can be used to instantiate sub-classes easily. This is almost identical to the same method John Resig had posted on his blog.

All of this brings JavaScript closer to something that would make a developer with mostly object-oriented experience more comfortable.

Finally, he makes his first touch on regular expressions, which is the basis of the next chapter. I’ll be reading this with the following quote in mind:

You have a problem, so you use a regular expression to solve it. Now you have two problems.

What I Learned in this Chapter

John went more in depth (and more plainly) about why extending the prototype of native objects could be bad. He also showed a clever way for a function to detect whether is was called as a direct invocation vs. as a constructor.