Javascript: Abusing "this"

Really quick tutorial.

► Javascript has a keyword called "this".

► "this" is a global variable

► Whenever I call a method, "this" gets set to that method's current location.

► It's important to remember that "this" isn't a property unique to any object or context at compile time - when you use it in code it is always a reference to the global variable set at run time (when you call the method).

Call and Apply

► Allow us to assign what "this" is for the duration of a method call.

► This is essentially how Javascript creates objects in the first place.

► Allows us to break OOP and shove it in Javascript's smug little face.

Cats and dogs living together

What else can we do with it?

Why won't JS let me push array elements onto numbers?

Javascript cares that I only call existing methods. It doesn't check for "this" though.

Computers are stupid :)

Anything mildly legitimate we could do with it?

Inheritance the correct way (as stolen from John Ressig)

Heck if I'm doing that.

Check it out, multiple inheritance!

Javascript is messed up.

/