Error
constructor creates an error object.
new Error([message[, fileName[, lineNumber]]])
message
可选
A human-readable description of the error.
fileName
可选
fileName
property on the created
Error
object. Defaults to the name of the file containing the code that called the
Error()
构造函数。
lineNumber
可选
lineNumber
property on the created
Error
object. Defaults to the line number containing the
Error()
constructor invocation.
When
Error
is used like a function -- without
new
, it will return an
Error
object. Therefore, a mere call to
Error
will produce the same output that constructing an
Error
object via the
new
keyword would.
// this...
const x = Error('I was created using a function call!')
// ...has the same functionality as this.
const y = new Error('I was constructed via the "new" keyword!')
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Error constructor' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Error()
构造函数
|
Chrome 1 | Edge 12 | Firefox 1 | IE 6 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
Error
EvalError
InternalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()