3 ms·
I really like the way scheme does it. In order to mutate a variable (which is actually comparatively rare), you have to use `set!`, and to create a binding (mu
by jayferd 13y ago
I really like the way scheme does it. In order to mutate a variable (which is actually comparatively rare), you have to use `set!`, and to create a binding (much more common), you just call `define`. `set!` is incapable of creating new bindings, and will error if the variable is in scope, while `define` will always shadow.
The js and coffeescript ways of handling this seem both to come down to the assignment operator being used for both creating bindings and mutating them, which gets confusing, and causes the failure modes you described.
- masklinn 13y ago> The js and coffeescript ways of handling this seem both to come down to the assignment operator being used for both creating bindings and mutating them That is not quite the case in javascript, `var` creates a binding (also `let` in ES6), and assignment assigns to the binding. There is the issue that assigning to an non-existant binding creates a global one, but strict mode will turn it into an error and linters have little issue recognizing and warning against it either.
- jayferd 13y agoHm, but it seems to be a runtime error. Is there a transpiler or other tool that will give you static errors if you try to set an out-of-scope variable?
- masklinn 13y ago> Hm, but it seems to be a runtime error. Yes, it's still javascript. > Is there a transpiler or other tool that will give you static errors if you try to set an out-of-scope variable? Elm and Fay likely do.
- jayferd 13y agoJust asked about this on #altjs, and it looks like TypeScript will actually give you a static error if you try to assign to a free variable.