On 17/01/2016 08:25, Chris Angelico wrote:
On Sun, Jan 17, 2016 at 6:37 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
Technically it defaults to non local. The var statement allocates a
variable within the current scope. Otherwise it searches up the chain of
parent scopes for a matching variable...
This far, it's exactly the same as C.
... terminating at the global scope.
This is the bit that gets ridiculous. Undeclared variables in C are
compile-time errors. Undeclared variables in JS are implicit globals.
This is stupid.
My own language is something in-between. If a name is not declared
locally, it will look at more global scopes. If nothing is found, it
will auto-declare a local.
So the JS bug wouldn't occur. However, there is the problem that, given
a perfectly working function with implicitly locals, at some point in
the future someone could introduce a global that will clash with the
name of a local, and screw things up.
Because of that, the Python scheme is better on the whole. The only
issue is that sometimes you think you're assigning to a global, but it's
really a local if you forget the 'global' declaration within the function.
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list