Live data from Hacker News

Is JavaScript getting worse?

buzzdecafe.github.io

11–20 of 117 posts

Re: Is JavaScript getting worse?

#11
> This means that typeof can now throw

    >>> 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.

Re: Is JavaScript getting worse?

#14
post #10

I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?

Fat arrow notation massively increases readibility by reducing the boilerplate verbosity of function definitions. Lexical "this" binding means that the "this" of the enclosing scope is reused; Arrow-defined functions do not get their own "this" when they are called.

Re: Is JavaScript getting worse?

#15
post #10

I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?

It means it inherits the 'this' of the enclosing function.

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?

#16

This is one of the few posts about javascript that I've encountered that sees hoisting as a good thing. I like `let`.

That part of the article isn't particularly clear. The intended behavior of let is great. The unintended behavior - that it can cause typeof to fail - is bad.

Re: Is JavaScript getting worse?

#17

Earlier 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.

What you have to keep in mind is that JavaScript is not "a properly scoped language". Pretending that it is will cause you to miss key aspects of how the tool works. This helps no one, including you. Please, for as crappy as the language might feel, approach the language on its own terms.

Re: Is JavaScript getting worse?

#18
post #10

I don't understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical "this" binding mean?

A lot of times you stuff the context (this) into a variable (like that)... so that you can use it in callback handlers farther down.

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?

#20
Whoop-dee-freakin’-doo???

Sure 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.)

Post reply on HN