9 ms·
> Var is broken in js because it does not obey sensible semantics Scoping is broken in pretty much all modern dynamic languages. Take Ruby for example: i
by jd 15y ago
> Var is broken in js because it does not obey sensible semantics
Scoping is broken in pretty much all modern dynamic languages.
Take Ruby for example:
i = 10
[1, 2, 3].map{|i| i * 3}
[1, 2, 3].map{|j| j * 3}
puts i # prints 3
puts j # raises undefined local variable
Or let's look at Python:
def maybe_append(b=[], n = None):
if not n is None: b.append(n)
return b
print maybe_append(n=20) # prints [20]
print maybe_append(n=30) # prints [20, 30]
So there's only a single instance of [], so that the default argument "grows" over time.
- moonchrome 15y agoIt's things like this that make me realize how right Clojure gets it (and I've been burned by python on that same "bug").