title: Extending Error in Javascript with ES6 syntax & Babel
body: <p>I am trying to extend Error with ES6 and Babel. It isn't working out.</p>
  
  <pre><code>class MyError extends Error {
    constructor(m) {
      super(m);
    }
  }
  
  var error = new Error("ll");
  var myerror = new MyError("ll");
  console.log(error.message) //shows up correctly
  console.log(myerror.message) //shows empty string
  </code></pre>
  
  <p>The Error object never get the right message set.</p>
  
  <p><a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=false&amp;code=class%20MyError%20extends%20Error%20%7B%0A%20%20constructor(m)%20%7B%0A%20%20%20%20super(m)%3B%0A%20%20%7D%0A%7D%0A%0Avar%20error%20%3D%20new%20Error(%22ll%22)%3B%0Avar%20myerror%20%3D%20new%20MyError(%22ll%22)%3B%0Aconsole.log(error.message)%20%2F%2Fshows%20up%20correctly%0Aconsole.log(myerror.message)%20%2F%2Fshows%20empty%20string" rel="noreferrer">Try in Babel REPL</a>.</p>
  
  <p>Now I have seen a few solutions on SO (<a href="https://stackoverflow.com/questions/8802845/inheriting-from-the-error-object-where-is-the-message-property">for example here</a>), but they all seem very un-ES6-y. How to do it in a nice, ES6 way? (That is working in Babel)</p>