classes and enumerability

Rick Waldron waldron.rick at
Tue Dec 23 17:17:43 PST 2014

On Tue Dec 23 2014 at 7:35:44 PM Andrea Giammarchi <
andrea.giammarchi at> wrote:

> Dear Santa,
>   I wish since ES3 era that properties defined on a prototype are by
> default **not** enumerable.

> By any chance we can make this happen in ES6 classes?

ES6 is done, properties of user created prototypes are enumerable by
default. They can be made non-enumerable if you want them that way, but
doing so by default is inconsistent with constructor function + prototype

> Or better ... why would anyone expect or want them to be enumerable?

- Consistency with constructor function + prototype definition (severe
refactoring hazard).
- Pretty useful for dynamically creating collection APIs, eg:

  Object.keys(Servo.prototype).forEach(function(method) {
    // Create `Servos` collection class wrappers for each method
    Servos.prototype[method] = function() {
      var args = [];
      this.each(function(servo) {
        Servo.prototype[method].apply(servo, args);
      return this;

> To define a `class` is a very explicit intent, I believe having those
> definitions non enumerable would be a preferred option for majority of
> developers that have been doomed in `for/in` since kinda ever before
> enumerable was not configurable.
> All default methods and properties in native prototypes are **not**
> enumerable, why does it have to be so inconsistent with userland?

The widely understood, wholly well-known semantics:

- Properties of built-in prototype objects are non-enumerable
- Properties of user defined prototype objects are enumerable by default,
but can be made non-enumerable if desired.

> You also know ES6 is the only window we have 'cause after that it will be
> a breaking change.

No: any future annotation syntax must allow for defining writable,
configurable and enumerable attributes.

> Thank you at least for any sort of extra/concrete clarification about this
> choice.


The consistency argument has won every time this conversation is brought
up. There are ways to get what you want in the future (probably even in
ES7), but changing the default is not the solution.

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

More information about the es-discuss mailing list