2 ms·
It would be my instinct to hoist the walk() function out of the parse() function but that's because my compiler writing experience is limited to C and Pascal. W
by tomcam 5y ago
It would be my instinct to hoist the walk() function out of the parse() function but that's because my compiler writing experience is limited to C and Pascal. What is the thinking behind this decision? Not criticism, just trying to learn Javascript better
- colejohnson66 5y agoLocal functions like that make sense if you want to access the outer function’s state - which is what’s happening here with `current`. It also makes it so others can’t use that function without having to make a separate module. Almost like a scoped “global” state. See also: IIFEs: https://developer.mozilla.org/en-US/docs/Glossary/IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
- tomcam 5y agoOf course! Totally obvious… Now that you bring it up! That’s much nicer than my non-scoped instinct. Thank you.