Object Oriented JavaScript study group

After getting a good deal of the way through Professional JavaScript for Web Developers over the summer, Denver Code Club has been reading Nicholas Zakas‘ new Principles of Object Oriented JavaScript book for the past few weeks. It’s a great, quick read (6 chapters, 93 pages) so far, though very dense. It’s taking me a little longer to get through it because I’m re-reading a lot of the material to make sure I understand it.

There have been quite a few “a-ha!” moments while reading, including:

  • Just how useful property access using the bracket notation is:
  • Not just what hoisting is, but when it works:
  • That there’s an arguments object associated with each function. The obvious benefit is that it can be used to accept any number of function parameters:

Throughout the book, Zakas gives general insight into how JavaScript processes behind the scenes; Information which I find pretty valuable.

However, I got to chapter 3 and ran into a little confusion regarding call(), .apply(), and .bind(). Realizing I needed a this keyword refresher, I re-read these articles by Richard Bovell and David Flanagan:

Because this refers to the execution context, not the current object, sometimes we have to use a function like .apply() and .call() to set the scope explicitly. They both assign a different this object when calling an existing function and the only difference is that .call() accepts an any number of arguments .apply() accepts an array of arguments.

The .bind() function returns a new function with the this value of the new function set to the provided argument. I need to remember not to pass in this as a parameter or cache it in a variable to use inside a nested function, but to use .bind() instead.

Closures are when an inner function has access to the outer functions parameters. For some reason, it wasn’t immediately obvious that the outer function returned another function, not a variable:

A coworker coined a term for my literary adventures:

wordhole (n): A common phenomenon occurring while reading technical literature, in which the reader is sucked into a continual search for meaning that only provides new depths of confusion.

After all of my research, I took the JavaScript Scope Quiz – 6 out of 7 right. Not bad, but I could use improvement. Next on my reading list are the “You Don’t Know JavaScript” books (this & Object Prototypes and Scope & Closures).

It’s been a busy summer, but I’m glad to be back learning, reading, and programming at the coffees shop on my weekend mornings.