An "extend" operator is a natural companion to <|

Bob Nystrom rnystrom at google.com
Mon Jul 18 17:31:48 PDT 2011


On Mon, Jul 18, 2011 at 4:59 PM, Brendan Eich <brendan at mozilla.com> wrote:

>  The primary purpose of a class is to define the behavior (methods) of
>> instances. It is describing an abstraction over all the possible instances.
>> The behavior of the singleton class object is typically secondary to the
>> primary abstraction.
>>
>
> True, but secondary still matters.
>
> Here you were arguing about class vs. prototype method indentation or body
> nesting level?
>

I think Allen was explaining why it makes sense for "static" methods to be
in a second curly block following the main class definition.

I could see us making a subordinate body for class methods, instead of using
> 'static'.


Interesting idea! Something like this?

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  manhattanDistance() {
    return Math.abs(this.x) + Math.abs(this.y);
  }

  ??? {
    zero() {
      return new Point(0, 0);
    }

    unit() {
      return new Point(1, 1);
    }
  }
}

It looks a little strange to me to lump the class members together like that
and leave the prototype ones directly under class given that the prototype
members don't end up on the class. You could flip it around to:

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  zero() {
    return new Point(0, 0);
  }

  unit() {
    return new Point(1, 1);
  }

  prototype {
    manhattanDistance() {
      return Math.abs(this.x) + Math.abs(this.y);
    }
  }
}

Pros:
1. Makes it abundantly clear that prototype members are just that.
2. Makes it clearer (I think?) that members on the constructor ("class") are
that. Basically, the name of the surrounding curly ("prototype" or "class")
tells you where the member goes.

Cons:
1. Prototype members, the most common case, are the most verbose and suffer
two levels of indentation.
2. constructor() is in weird limbo. Should it be under prototype or class?
3. Lots'o'curlies.

There may be a good solution hiding in here somewhere, but I'm not sure.

- bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110718/566147d8/attachment.html>


More information about the es-discuss mailing list