alignment with es6 classes (prototype/instance properties)

Topics: Language Specification
Jun 20, 2013 at 3:48 PM
In latest es6 spec is possible to define prototype properties as well as per-instance properties.
In typescript we can define only methods as prototype properties (or use ugly "out of class" definitions). I miss this feature a lot.
Someone says prototype properties will be confusing, but why?
In es6 prototype and instance properties are written differently in very "easy to understand" way.

Example:
class Monster {

  // declare and initialize per-instance properties.erties.
  constructor(name, health) {
    public name = name;
    private health = health;
  }

  // declares a prototype property and initializes it to the value of that expression. 
  public numAttacks = 0;
}
Are you going to implement this in some next version (1.x) ?
link to harmony spec
Coordinator
Jun 24, 2013 at 4:18 PM
I suspect we won't align completely before 1.0. There are some features, like class expressions, we don't yet support (though I believe we could in theory, we just haven't put the resources into it, yet). We'll likely explore more alignment post 1.0.
Jun 25, 2013 at 1:49 AM
Do you guys plan to release TS 1.0 before the ECMAScript spec is complete? Seems like that could make it more difficult to change things if the spec changes further.
Jun 26, 2013 at 8:32 PM
@dorny, at the head of your link to the harmony spec it says: "This proposal has been superseded by the “Maximally Minimal Classes”".

The link to the latter is here http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes

In that spec we have:
// The only way to create prototype data properties is by
// modifying the prototype outside of the declaration.
Monster.prototype.numAttacks = 0;
This is what we currently get with TypeScript.

Personally, I cannot see any benefit in the monster example you have posted. That appears to be imposing a penalty on the more common usage (instance properties) and favouring a generally rare use-case (prototype properties).

If you have any common use cases for putting properties on the prototype then it should be interesting to see them.
Jun 27, 2013 at 9:45 AM
@nabog , you are right. I saw on that page only what i wont and miss "superseded" message on top.
If es6 decided to use "Maximally Minimal Classes", my opinion is totally irrelevant.
Sorry for useless topic.
Coordinator
Jun 27, 2013 at 2:09 PM
The ECMAScript 6 completion is (or at least was) a bit of a moving target. What we've opted to do, in the module case for example, was to try to align the syntax in a way that we could add in the ES6 features on top of the existing TypeScript ones. This means we're picking minimal syntax in places with a lot of churn in the ES6 spec so we fill it out later once the ES6 spec is complete.