Enumerability

Rick Waldron waldron.rick at gmail.com
Sun Jan 12 21:01:24 PST 2014


On Sun, Jan 12, 2014 at 11:45 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> Rick, what you wrote has _nothing_ to do with inheritance, right? So why
> should "classes" methods be part of a for/in of an instance, which is not
> what you wrote, again?
>

Sometimes I find you incredibly frustrating to communicate with. You asked
me to give an example of "expected to be enumerable" and I did so by
providing an example in the form that I made my original argument for
revisiting the decision to make concise method definitions non-enumerable.
Specifying concise method definitions to be enumerable: true in all cases
is consistent with defining a method on a prototype object today:


  function C() {}
  C.prototype.method = function() {};

  for (var p in C.prototype) {console.log(p)}

  > method

Refactor #1:

  function C() {}
  C.prototype = {
    constructor: C,
    method() {}
  };

  for (var p in C.prototype) {console.log(p)}

  > method

Refactor #2:

  class C {
    method() {}
  }

  for (var p in C.prototype) {console.log(p)}

  > method


Now that I've described as clearly as I possibly can, I hope the point of
making concise method definitions—regardless of which syntactic body form
they appear in—produce an enumerable: true property is clear to you and
that my answer has sufficiently met your need.

Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140113/e6059157/attachment-0001.html>


More information about the es-discuss mailing list