Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh-cn: update the translation of Error.prototype.name #24205

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
---
title: Error.prototype.name
slug: Web/JavaScript/Reference/Global_Objects/Error/name
l10n:
sourceCommit: 6b728699f5f38f1070a94673b5e7afdb1102a941
---

{{JSRef}}

## 概述
`Error.prototype` 的 **`name`** 数据属性是所有 {{jsxref("Error")}} 实例所共享的。它表示当前错误类型的名称。对于 `Error.prototype.name`,其初始值为 `"Error"`。像 {{jsxref("TypeError")}} 和 {{jsxref("SyntaxError")}} 这样的子类会提供它们自己的 `name` 属性。

**`name`** 属性表示 error 类型的名称。初始值为"Error".
## 值

字符串。对于 `Error.prototype.name`,其初始值为 `"Error"`。

{{js_property_attributes(1, 0, 1)}}

## 描述

默认情况下,{{jsxref("Error")}}对象的`name`属性值为"Error".`name 属性和`{{jsxref("Error.prototype.message", "message")}}属性一起,通过调用{{jsxref("Error.prototype.toString()")}}方法,会作为最后异常信息的字符串表示
默认情况下,{{jsxref("Error")}} 实例提供的名称为“Error”。{{jsxref("Error.prototype.toString()")}} 方法会同时使用 `name` 和 {{jsxref("Error/message", "message")}} 属性来创建错误信息的字符串表示

## 示例

### 示例:抛出一个自定义错误
### 抛出一个自定义错误

```js
var e = new Error("Malformed input"); // e.name 默认是"Error"
const e = new Error("Malformed input"); // e.name 为“Error

e.name = "ParseError"; // 修改之后,e.toString() 会成为下面这样的字符串
throw e; // "ParseError: Malformed input"
e.name = "ParseError";
throw e;
// e.toString() 会返回“ParseError: Malformed input”
```

## 规范
Expand Down