Resum
La propietat name representa un nom per al tipus de error. El valor que rep inicialment aquesta propietat és "Error".
Descripció
Per defecte, les instàncies de Error reben el nom "Error". El mètode Error.prototype.toString() utilitza la propietat name combinada amb la propietat message per a crear una representació de l'error.
Exemples
Exemple: Llençar un error personalitzat
var e = new Error('Entrada no vàlida'); // e.name is 'Error'
e.name = 'ParseError';
throw e;
// e.toString() would return 'ParseError: Entrada no vàlida'
Especificacions
| Especificació | Estat | Comentaris |
|---|---|---|
| ECMAScript 1a Edició. | Standard | Definició inicial. |
| ECMAScript 5.1 (ECMA-262) The definition of 'Error.prototype.name' in that specification. |
Standard | |
| ECMAScript 6 (ECMA-262) The definition of 'Error.prototype.name' in that specification. |
Release Candidate |
Compatibilitat amb navegadors
| Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |