Aug 24, 2011

What is 'this'? - Revealing JavaScript's 'this' in different contexts

Understanding the value of ‘this’ in JavaScript as it appears in different contexts is a requisite to becoming an intermediate or advanced JavaScript programmer.

Closures, instantiations, ‘apply’, and ‘with’ all can change what ‘this’ is. Here’s a little guide to help show you how. How many would you have guessed correctly? :)

You can paste the gist into node or your console and you should see the tests pass. If you have some examples to add, fork the gist and add them!

Question or comment?