我正在尝试使用ES6和Babel扩展Error,但似乎无法实现。
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
Error对象从未获得正确的消息设置。
现在我已经看到 SO 上的一些解决方案 (例如这里),但它们似乎都不是很符合 ES6 的风格。如何以一种美观、ES6 的方式实现呢?(能在 Babel 中工作的那种)