top | item 13336741

(no title)

imagist | 9 years ago

I know Javascript well enough to avoid it when possible.

discuss

order

matthewaveryusa|9 years ago

ECMAScript6 is a wonderful language that approaches the syntactic readability of python. If you're stuck with ECMAScript5 sure, go ahead and say javascript is terrible because it is. But ECMAScript6? No way. They fixed so many annoying things. the fat arrow that captures "this", proper classes and inheritance, maps and sets and string template literals are the biggest ones that jump to mind. es6 is to javascript like what c++11 is to c++ -- it made it so you don't have to use the warts. ECMAScript6 snippet:

  class Shape {
      constructor (id, x, y) {
          this.id = id
          this.move(x, y)
      }

      move (x, y) {
          this.x = x
          this.y = y
      }

      fixed_offset(off_x,off_y) {
        return () => {
          console.log(`offsets x: ${off_x} y: ${off_y}`)
          return [this.x + off_x, this.y + off_y]
        };
      }
  }
And yes ECMAScript5 is gross:

  var Shape = function (id, x, y) {
      this.id = id;
      this.move(x, y);
  };
  Shape.prototype.move = function (x, y) {
      this.x = x;
      this.y = y;
  };
  Shape.prototype.fixed_offset(off_x,off_y) {
    var self = this;
    return function() {
      console.log("offsets x: " + off_x + " y: " + off_y`)
      return [self.x + off_x, self.y + off_y]
    }
  }

imagist|9 years ago

I do not care about the rearrangement of deck chairs on the Titanic that is ES6. I wouldn't care if JS were uglier than Erlang, if it worked as well.

The only people who care about ES6 classes are the ones who couldn't be bothered to learn how to use duck typed prototypes and were always trying to shoehorn in polymorphism. Prototypes were one of the few things Javascript had going for it, but adding classes means now there are two OO systems that don't interoperate. This is a new problem, not an improvement. There's a similar problem with callbacks and promises.

Other problems added in ES6: imports don't give an error when the thing I'm importing, continuing the JS tradition of handling errors by pretending everything is okay.

And this is in addition to the rotten core of JavaScript. There remains no integer type. Basic operators still take arguments of all types and return something regardless of whether it makes any sense. "this" still has little to do with this.

In any other language I'd complain about the lack of threading, but given JS can't handle easy stuff like implementing a sane comparison operator, it's probably better that they don't try anything legitimately difficult like threading.

arrakeen|9 years ago

and yet it also gives us this mess:

  import defaultMember from "module-name";
  import * as name from "module-name";
  import { member } from "module-name";
  import { member as alias } from "module-name";
  import { member1 , member2 } from "module-name";
  import { member1 , member2 as alias2 , [...] } from "module-name";
  import defaultMember, { member [ , [...] ] } from "module-name";
  import defaultMember, * as name from "module-name";
  import "module-name";

don't get me wrong, i think ES6 is much better than what we had before, but it still has a lot of warts