PPK describes the this keyword as a reference to the owner of the function we are executing, or the object that a function is a method of. He then compares how attaching a function to an event in two different ways affects what the this keyword references.
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.