相关疑难解决方法(0)

如何在JavaScript中创建自定义错误?

出于某种原因,看起来构造函数委派在以下代码段中不起作用:

function NotImplementedError() { 
  Error.apply(this, arguments); 
}
NotImplementedError.prototype = new Error();

var nie = new NotImplementedError("some message");
console.log("The message is: '"+nie.message+"'")
Run Code Online (Sandbox Code Playgroud)

运行这个给出The message is: ''.有关为什么,或者是否有更好的方法来创建新Error子类的任何想法?是否存在我不知道apply的本机构Error造函数的问题?

javascript exception

200
推荐指数
10
解决办法
13万
查看次数

标签 统计

exception ×1

javascript ×1