3 ms·
JavaScript Scope & "this"
- EvilTerran 14y agoThat covers it nicely. A couple of minor typos, though: You've got extraneous ")"s in the code-blocks under "Local Scope" and "A word of Caution", and I think the one under "very bad idea" needs the last line to be "})();" in place of just "});".
- exDM69 14y agoIf anyone ever wonders why Python has the explicit self-variable, this is the answer. If you define a local class inside a method inside a class, you will have two variables called "this" or "self" and it may be practical to refer to both of them. Sometimes you see JavaScript with "var self = this;" or something similar.
- psquid 14y agoA good read, but a little disappointing that it didn't touch on the (function(...) {...}).bind(this) approach to passing the parent "this" context down the function tree, preferring instead to use an extra variable in the form of "_this".