Hacker News new | ask | show | jobs
by chriswarbo 4181 days ago
I somewhat agree, but "adding tools" at the language level doesn't come for free: it causes an explosion in the number of interactions to keep track of. How do classes interact with prototypes? How do they interact with lexical scope? How do they interact with exceptions? etc.

The egregious part is that, by turning something into a language feature, those who don't use it are often forced to take it into account in their code; especially library authors.

1 comments

> those who don't use it are often forced to take it into account in their code; especially library authors.

No, `class` is syntactic sugar for the most common way of doing classes in ES3 and ES5. There is no semantic difference between:

    function Thing () {}

    Thing.prototype.greet = function () { alert("hello"); };
and

    class Thing {
      greet () {
        alert("hello");
      }
    }

They are the same, so it introduces no new traps for library authors.
About the only thing that might be interesting to see is how constructor parameters are handled. With the prototyping system, I consider it to be a bug to initialize members in the constructor - if you always just call an 'init' method straight after construction (typically chained, much like in Objective C - var thing = new Thing().init(param); ) then protyping is very simple and does nothing surprising. It's only if you really really really want to have RAII that things become complicated...