Repository navigation
Merged
Conversation
Contributor
|
Preview URLs External URLs (5)URL:
(comment last updated: 2024-05-07 04:58:45) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
|
||
| 许多内置复制方法都实现了这一行为。有关此功能的注意事项,请参阅 [subclassing built-ins](#subclassing_built-ins) 讨论。 | ||
|
|
||
| ### Mix-ins |
Contributor
There was a problem hiding this comment.
Suggested change
| ### Mix-ins | |
| ### 混入 |
本章节的其他mix-in也做一下翻译
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Comment on lines
+61
to
+63
| | | `ChildClass` 的原型对象 | `ChildClass.prototype` 的原型对象 | | ||
| | --------------------------------- | ----------------------- | --------------------------------- | | ||
| | `extends` clause absent | `Function.prototype` | `Object.prototype` | |
Contributor
There was a problem hiding this comment.
[mdn-linter] reported by reviewdog 🐶
Suggested change
| | | `ChildClass` 的原型对象 | `ChildClass.prototype` 的原型对象 | | |
| | --------------------------------- | ----------------------- | --------------------------------- | | |
| | `extends` clause absent | `Function.prototype` | `Object.prototype` | | |
| | | `ChildClass` 的原型对象 | `ChildClass.prototype` 的原型对象 | | |
| | ---------------------------- | ----------------------- | --------------------------------- | | |
| | `extends` clause absent | `Function.prototype` | `Object.prototype` | |
Member
There was a problem hiding this comment.
不应直接忽略,我们使用格式化工具格式化 markdown 表格。
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
yin1999
reviewed
May 7, 2024
| ``` | ||
|
|
||
| - `ParentClass` | ||
| - :求值为构造函数(包括类)或 `null` 的表达式。 |
| `extends` 关键字用来创建一个普通类或者内建对象的子类。 | ||
|
|
||
| 继承的 `.prototype` 必须是一个 {{jsxref("Object")}} 或者 {{jsxref("null")}}。 | ||
| 任何可以用 [`new`](/zh-CN/docs/Web/JavaScript/Reference/Operators/new) 调用并具有 [`prototype`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype) 属性的构造函数都可以作为父类的候选构造函数。这两个条件必须同时成立——例如,[绑定函数(bound functions)](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) 和 {{jsxref("Proxy")}} 可以被构造,但它们没有 `prototype` 属性,因此不能被子类化。 |
Comment on lines
+61
to
+63
| | | `ChildClass` 的原型对象 | `ChildClass.prototype` 的原型对象 | | ||
| | --------------------------------- | ----------------------- | --------------------------------- | | ||
| | `extends` clause absent | `Function.prototype` | `Object.prototype` | |
Member
There was a problem hiding this comment.
不应直接忽略,我们使用格式化工具格式化 markdown 表格。
| console.log(new ChildClass()); // TypeError: Derived constructors may only return object or undefined | ||
| ``` | ||
|
|
||
| 如果父类构造函数返回一个对象,则在进一步初始化[类字段(class field)](/zh-CN/docs/Web/JavaScript/Reference/Classes/Public_class_fields)时,该对象将被用作派生类的 `this` 值。这种技巧被称为[“返回覆盖”](/zh-CN/docs/Web/JavaScript/Reference/Classes/Private_properties#returning_overriding_object),它允许在无关对象上定义派生类的字段(包括[私有](/zh-CN/docs/Web/JavaScript/Reference/Classes/Private_properties)字段)。 |
Member
There was a problem hiding this comment.
同,英文注释是不必要的;此外,请注意 URL 的片段(hash,需要找到目标文档中文版本的标题)
| const m = new ReadOnlyMap([["a", 1]]); // TypeError: A read-only map must be set at construction time. | ||
| ``` | ||
|
|
||
| 我们可以通过使用一个私有标志来指示是否正在构造实例来解决这个问题。然而,这种设计的一个更重要的问题是,它破坏了[里氏替换原则](https://zh.wikipedia.org/wiki/%E9%87%8C%E6%B0%8F%E6%9B%BF%E6%8D%A2%E5%8E%9F%E5%88%99),该原则规定子类应该可以替换其超类。如果函数期望使用一个 `Map` 对象,那么它也应该能够使用一个 `ReadOnlyMap` 对象,这在这里就会被打破。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation
Additional details
Related issues and pull requests
extends part of #18329