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 description of the new operator #17065

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Changes from 4 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
11 changes: 7 additions & 4 deletions files/zh-cn/web/javascript/reference/operators/new/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ new constructor[([arguments])]

**`new`** 关键字会进行如下的操作:

1. 创建一个空的简单 JavaScript 对象(即 **`{}`**);
2. 为步骤 1 新创建的对象添加属性 **`__proto__`**,将该属性链接至构造函数的原型对象;
3. 将步骤 1 新创建的对象作为 **`this`** 的上下文;
4. 如果该函数没有返回对象,则返回 **`this`**。
1. 创建一个空的简单 JavaScript 对象(即 **`{}`**),为方便起见,我们称之为 `newInstance`;
2. 如果构造函数的原型属性是一个对象,将 `newInstance` 的[[Prototype]]指向构造函数的原型属性,否则 `newInstance` 将保持为一个普通对象,其 [[Prototype]] 为 `Object.prototype`;

> **注意:**:因此,通过构造函数创建的所有实例都可以访问添加到构造函数原型属性中的属性/对象。
yin1999 marked this conversation as resolved.
Show resolved Hide resolved

4. 使用给定参数执行构造函数,并将 `newInstance` 绑定为 **`this`** 的上下文;
yin1999 marked this conversation as resolved.
Show resolved Hide resolved
yin1999 marked this conversation as resolved.
Show resolved Hide resolved
5. 如果构造函数返回[非原始值](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Data_structures),则该返回值成为整个 `new` 表达式的结果。否则,返回 `newInstance`。(通常构造函数不返回值,但可以选择返回值,以覆盖正常的对象创建过程)
yin1999 marked this conversation as resolved.
Show resolved Hide resolved
yin1999 marked this conversation as resolved.
Show resolved Hide resolved

(译注:关于对象的 **`constructor`**,参见 **`Object.prototype.constructor`**)

Expand Down
Loading