In ES6:

class MyError extends Error {
  constructor(message) {
    super(message);
    this.name="MyError";
  }
}

source