From Mozilla: An overview of the object-oriented capabilities of JavaScript. This covers OO concepts of classes and objects, instances, abstraction, encapsulation and polymorphism as done in JavaScript with functions and prototypal inheritance.
Angus Croll takes the reader step-by-step through some basic JavaScript code explaining what 'this' is in each step and why. He explains how 'this' depends on the execution context, and how it is manipulated by how JavaScript functions are called (or applied or bound with bind), and how Constructors create a new context.
Tim Caswell describes the JavaScript variable 'this', which is about current scope and current context. The only way to create scope in JavaScript is through function definitions, and in most cases the context is the receiver of the message (the object before the dot in the method call). He also talks about approaches to controlling what this references with call, apply and bind.
Jonathan Snook demonstrates when JavaScript passes by reference or passes by value. Essentially, primitive types are passed by value, objects are passed by reference. Passing functions however, makes things look like a pass by value if the this
keyword is being used in the code. Snook offers workarounds to this by passing objects so that the context is correct, or using the call()
function to ensure the context is correct.