3 ms·
That is a common JS idiom because the binding of "this" changes inside function calls, so one must capture the outer binding of "this" which when used in an obj
by mdaniel 12y ago
That is a common JS idiom because the binding of "this" changes inside function calls, so one must capture the outer binding of "this" which when used in an object scenario does behave like the same keyword used in traditional OO. The naming of "self" could just be a synonym or a nod to Python (I'd have to do research to know definitively)
- beernutz 12y agoThat makes sense. I wonder though if there is a better convention than "self". That by itself (to me at least) does not say much about which "self" we are describing. Maybe it is just a matter of personal preference, but I like to be more specific and descriptive. It reminds me of the practice of using "throw-away" variables in for loops. Personally I would still rather name the variable "loop" instead of "i".
- mdaniel 12y agoOk, you are free to propose an alternative - either here or to your team - but be sure you and your team are prepared to have to adjust if and when you join another JS team. And if I had to name loop variables "loop" I would lose my mind. But I'm glad it works for you and your team, so long as you never have nested for loops.