Digital Web Magazine - Scope in JavaScript:
Scope is one of the foundational aspects of the JavaScript language, and probably the one I’ve struggled with the most when building complex programs. I can’t count the number of times I’ve lost track of what the this keyword refers to after passing control around from function to function, and I’ve often found myself contorting my code in all sorts of confusing ways, trying to retain some semblance of sanity in my understanding of which variables were accessible where...

What if we just call a normal, everyday function without any of this fancy object stuff? What does this mean in that scenario?

In this case, we weren’t provided a context by new, nor were we given a context in the form of an object to piggyback off of. Here, this defaults to reference the most global thing it can: for web pages, this is the window object.

OO Javascript is neat, but I agree completely; scope is a real pain.

This link brought to you, well, via me, but to me via a post on Stackoverflow by superstar Jon Skeet.  The man is good.

Labels: