Sep 27 meeting notes

Bob Nystrom rnystrom at
Thu Sep 29 17:08:44 PDT 2011

On Thu, Sep 29, 2011 at 4:22 PM, Erik Arvidsson <erik.arvidsson at>wrote:

> However, it seems like all the issues we have seen are due to us
> trying to solve issues that already exist today with prototype based
> "classes". These involve (but are not limited to):
> 1. Don't let uninitialized objects escape
> 2. Ensure the shape of the instance
> 3. Initialization of instance properties
> 4. Allow const classes
> 5. Allow const properties
> 6. Play well with future type guards

I was tinkering with some syntax ideas last night and had the same
revelation. It feels like we've over-constrained ourselves. In particular,
if you're willing to discard 2 and 6 (basically not worry about a
declarative form for instance properties) I think it gets a lot easier.

If we throw in the sections stuff that we discussed a while back, that could
give you something like:

class Monster {
  constructor(, {}

  attack(target) {

  get isAlive() {
    return > 0;

  set health(value) {
    if (value < 0) throw new Error('Health must be non-negative.') = value

  let numAttacks = 0;

  const attackMessage = 'The monster hits you!';

This means:

- A class body contains only definitions. By default those definitions
become properties on the prototype. You can change that by adding a section.
Everything after class: goes on the constructor.

- Instance properties are not declared explicitly. But allowing "this." in
the constructor argument list gives you a nice notation for automatically
initializing them from arguments.

- Here I'm using "let" to declare a mutable data property in the class body.
We could use whatever. It's a pretty open field since the body doesn't
contain arbitrary statements.

This is pretty close to how both Ruby and Python classes behave and I
> think we don't have to solve the problems raised above for

I like this. Maybe in pursuit of perfect we've lost sight of good?

- bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list