【发布时间】:2017-01-18 02:49:04
【问题描述】:
export class InvalidCredentialsError extends Error {
constructor(msg) {
super(msg);
this.message = msg;
this.name = 'InvalidCredentialsError';
}
}
正如你在上面看到的,我写了两次InvalidCredentialsError。有没有办法以某种方式在构造函数方法中获取类名并设置它?还是必须实例化对象?
【问题讨论】:
-
您在寻找this.constructor.name吗?
-
@CodingIntrigue
this.constructor.name返回“错误”。 -
奇怪。这可能是子类化
Error的问题,因为我不明白为什么它不会返回当前的类名。
标签: ecmascript-6