I've been thinking about something Brendan said in his last podcast about
how the community and TC39 can't agree on the syntax for class initializers
because of how flexible he made it at the beginning. So a little idea came
to me.

How about adding an Object.getMetaProperties or Function.getMetaProperties
method to retrieve the meta properties of an object/class initializer,
regardless of where they were declared (inside or outside)? That way the
community could extend the syntax to fit different styles. Combined with
proxies it could lead to many different multiple inheritance or mixin
patterns, as well as other interesting applications I'm probably missing.

Of course, this would be extra useful if meta properties where defined
outside the class/object body, because there's not much difference between
writing

class A {
  <superclass: B, uses: [C]>
}

or

class A {
  <superclass: B>,
  class var USES: [C]
}

...as we do today using constructor properties to add extra functionality.

Being able to write somethink like...

class A uses [C, D] {
  new () {
    let extensions = Function.getMetaProperty(A, 'uses') || [];
    extensions.forEach(#(ext) {
        // Copy ext prototype methods to A
    });
  }
}

...could be useful and fun.

Juan
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to