>>> def f():
... type(x)
... x = 10
...
>>> f()
Traceback (most recent call last):
File "", line 1, in
File "", line 2, in f
UnboundLocalError: local variable 'x' referenced before assignment
irb(main):010:0> def f()
irb(main):011:1> x.class
irb(main):012:1> x = 10
irb(main):013:1> end
=> nil
irb(main):014:0> f()
NameError: undefined local variable or method `x' for main:Object
from (irb):11:in `f'
from (irb):14:in `evaluate'
from org/jruby/RubyKernel.java:1101:in `eval'
from org/jruby/RubyKernel.java:1501:in `loop'
from org/jruby/RubyKernel.java:1264:in `catch'
from org/jruby/RubyKernel.java:1264:in `catch'
from C:/jruby-1.7.12/bin/jirb_swing:53:in `(root)'
public class Test {
public void f() {
boolean isInt = x instanceof Integer;
Integer x = 10;
}
}
>javac Test.java
Test.java:3: error: cannot find symbol
boolean isInt = x instanceof Integer;
^
symbol: variable x
location: class Test
1 error
Oh no, it's now in line with just about every other lexically scoped language.Is JavaScript getting worse?
11–20 of 117 posts
Re: Is JavaScript getting worse?
#12Betteridge's law[1] strikes again. [1] http://en.wikipedia.org/wiki/Betteridge%27s_law_of_headlines
Re: Is JavaScript getting worse?
#13Betteridge's law[1] strikes again. [1] http://en.wikipedia.org/wiki/Betteridge%27s_law_of_headlines
Re: Is JavaScript getting worse?
#14I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?
Re: Is JavaScript getting worse?
#15I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?
Without fat arrow: function outer() { function inner() { this === inner.this; } }
With fat arrow: function outer() { var inner = => this === outer.this; }
Re: Is JavaScript getting worse?
#16This is one of the few posts about javascript that I've encountered that sees hoisting as a good thing. I like `let`.
Re: Is JavaScript getting worse?
#17Earlier quoted context omitted.
Have you read the linked article about typeof? Normally, it's safe to do typeof possiblyUndeclaredVariable, but if later in the function you do let possiblyUndeclaredVariable it starts the scope defined as "uninitialized", which causes typeof to throw.
Well that's perfectly normal in a properly scoped language.
Re: Is JavaScript getting worse?
#18I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?
Fat arrow syntax is much more terse than a function declaration and also handles the case of passing the parent's execution scope.
Re: Is JavaScript getting worse?
#19Re: Is JavaScript getting worse?
#20Sure there's a zillion frameworks and patterns for shoehorning OO into JavaScript. But the point is, ES6, is standardising it. That means libraries going forward will assume this is the way it's done and build on top of it. It gives them more expressive power and better inter-op.
Also, default params are long overdue but I'm not sure that makes them "so what". I'd rather avoid mangling the arguments array in some awkward if statements.
Bottom line, there's a lot of things about JS that aren't great, but it's what all the browsers actually run so we're kind of stuck with it and any improvements are welcome.
(Even if you use something like ClojureScript or CoffeeScript, JS is still the target language and the runtime. Improvements and standardisation matter.)