Class syntax enhancements

Kagami Rosylight saschanaz at outlook.com
Tue Sep 27 04:10:17 UTC 2016


I’m not sure it’s okay to reply on this very old thread, but if I’m understanding correctly the desugared code can be fairly short with new Object.getOwnPropertyDescriptors:

```js
function partial(base, extension) {
  extension.prototype.__proto__ = base.prototype.__proto__; // to enable 'super' reference
  const descriptors = Object.getOwnPropertyDescriptors(extension.prototype);
  delete descriptors.constructor; // must not override constructor
  Object.defineProperties(base.prototype, descriptors);
  
  return base;
}
```

```
class A {
  foo() {
    return "foo"
 }
}

class B extends A {
}

partial(B, class {
  foobar() {
    return `${super.foo()}bar`;
  }
})

output.value = new B().foobar(); // will be “foobar;
```

This sample currently only works on Firefox 50+. https://jsfiddle.net/v8bbvavv/

Sent from Mail for Windows 10

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160927/d359e790/attachment.html>


More information about the es-discuss mailing list