I'm reading some JavaScript for work and have come across a section of code I'm finding interesting. I've done some reading and came across:
Is using 'var' to declare variables optional?
Which illuminates the lack of a var type declaration as putting the var into a scope bubbling mutable global-not-global state.
Example:
var foo = bar // locally scoped
foo = bar // outer scope, can have global ramifications
My question here is when combining outer scope declarations with anonymous functions, is this acceptable and what would be the recommended way of handling this? Is it "good" convention? Should this be locally scoped? It is inside a class for my purposes, so I see no reason why it would be anything other than locally scoped. Again, JS noob though, so looking for some insights.
Example:
updateThing = (e) => {
this.state.items = e.target.value;
}
Much appreciated, thanks.