`This` in javascript

added by Robert Waggott
12/8/2014 9:27:56 AM


Coming from a sane language you might think that this in JavaScript is kind of like this in an object oriented language like Java, something that refers to values stored in instance properties. Not so. In JavaScript it is best to think of the this as a boggart carrying a bag of data with an undetectable extension charm.


Bob Senoff
12/8/2014 10:09:54 AM
Nice find Robert!

Drew Peterson
12/8/2014 6:57:03 PM
I wonder how different things would be if they had named it 'context', rather than 'this'. I'm sure there would still be confusion as to what the context is at that moment, but I feel like the semantics make a big difference here. People coming from an OOP background have certain expectations of 'this', which I'm sure accounts for most struggles with understanding it in the Javascript world.