export default class Worker {
  constructor() {

    // EventTarget
    var delegate = document.createDocumentFragment();
    [
      'addEventListener',
      'dispatchEvent',
      'removeEventListener'
    ].forEach(f =>
      this[f] = (...xs) => delegate[f](...xs)
      )
  }

  postMessage(aMessage, transferList) {

    let e = new class extends CustomEvent {
      constructor() {
        super('message', {bubbles: false, cancelable: true})
      }
      get data() {
        return aMessage
      }
      get ports() {
        let ret = []
        (transferList || []).forEach(function(transfer) {
          if (transfer instanceof MessagePort) {
            ret.push(transfer)
          }
        })
        return ret.length > 0 ? ret : null
      }
    };

    if (this.onmessage) {
      this.onmessage(e);
    }

    this.dispatchEvent(e);
  }

}

export default class Worker {
  constructor() {
    // EventTarget
    var delegate = document.createDocumentFragment();
    [
      'addEventListener',
      'dispatchEvent',
      'removeEventListener'
    ].forEach(f => /*this[f]*/ Worker.prototype[f] = (...xs) => delegate[f](...xs))
  }
  postMessage(aMessage, transferList) {
    let e = new class extends CustomEvent {
      constructor() {
        super('message', { bubbles: false, cancelable: true })
      }
      get data() {
        return aMessage
      }
      get ports() {
        let ret = []
        (transferList || []).forEach(transfer => {
          if (transfer instanceof MessagePort) {
            ret.push(transfer)
          }
        })
        return ret.length > 0 ? ret : null
      }
    };
    if (this.onmessage) {
      this.onmessage(e);
    }
    this.dispatchEvent(e);
  }

}

Create worker methods at prototype level
Update: Create worker methods at prototype level

This approach is slightly faster since the code is executed only once.
Rather constructor code is executed every time a new instance is created.

Serious advantage of prototype over constructor is that the former is compatible with class inheritance.
