From 659a746f739e72cc83a4613851cc1930c4146ece Mon Sep 17 00:00:00 2001 From: Jason Lam Date: Thu, 23 Nov 2023 10:16:10 +0800 Subject: [PATCH 1/4] [zh-cn]: add the translation of ArrayBuffer.maxByteLength (#17074) Co-authored-by: Jason Ren <40999116+jasonren0403@users.noreply.github.com> --- .../arraybuffer/maxbytelength/index.md | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/arraybuffer/maxbytelength/index.md diff --git a/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/maxbytelength/index.md b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/maxbytelength/index.md new file mode 100644 index 00000000000000..5c682ead19f0da --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/maxbytelength/index.md @@ -0,0 +1,42 @@ +--- +title: ArrayBuffer.prototype.maxByteLength +slug: Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength +--- + +{{JSRef}} + +{{jsxref("ArrayBuffer")}} 实例的 **`maxByteLength`** 访问器属性返回该数组缓冲区可调整到的最大长度(以字节为单位)。 + +{{EmbedInteractiveExample("pages/js/arraybuffer-maxbytelength.html")}} + +## 描述 + +`maxByteLength` 属性是一个访问器属性,其设置访问器函数为 `undefined`,这意味着你只能读取此属性。该值在构造数组时通过 {{jsxref("ArrayBuffer/ArrayBuffer", "ArrayBuffer()")}} 构造函数的 `maxByteLength` 选项设置,并且不能更改。 + +如果该 `ArrayBuffer` 已分离,则该属性返回 0。如果该 `ArrayBuffer` 构造时未指定 `maxByteLength` 值,则该属性返回 `ArrayBuffer` 的 {{jsxref("ArrayBuffer/byteLength", "byteLength")}} 值。 + +## 示例 + +### 使用 maxByteLength + +在该示例中,我们创建一个 8 字节缓冲区,该缓冲区可调整到的最大长度为 16 字节,然后返回其 `maxByteLength`: + +```js +const buffer = new ArrayBuffer(8, { maxByteLength: 16 }); + +buffer.maxByteLength; // 16 +``` + +## 规范 + +{{Specifications}} + +## 浏览器兼容性 + +{{Compat}} + +## 参见 + +- {{jsxref("ArrayBuffer")}} +- {{jsxref("ArrayBuffer.prototype.byteLength")}} +- {{jsxref("ArrayBuffer.prototype.resize()")}} From 74e1b524cd5883af591880f98af3677c64e6eb49 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:56:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?chore(zh-cn):=20batch=20replace=20'?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=93=BE=E6=8E=A5'=20to=20'=E5=8F=82?= =?UTF-8?q?=E8=A7=81'=20part=203=20(#17069)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Allo --- .../reference/classes/static/index.md | 8 ++++---- .../web/javascript/reference/errors/index.md | 4 ---- .../reference/errors/json_bad_parse/index.md | 2 +- .../reference/errors/not_a_constructor/index.md | 4 ++-- .../reference/functions/arguments/index.md | 2 +- .../functions/arguments/length/index.md | 4 ++-- .../functions/arrow_functions/index.md | 2 +- .../functions/default_parameters/index.md | 7 +++++-- .../javascript/reference/functions/get/index.md | 2 +- .../functions/rest_parameters/index.md | 17 ++++++++--------- .../global_objects/arraybuffer/slice/index.md | 2 +- .../global_objects/atomics/store/index.md | 2 +- .../global_objects/bigint/bigint/index.md | 8 ++++---- .../reference/global_objects/bigint/index.md | 8 +++----- .../global_objects/boolean/valueof/index.md | 2 +- .../global_objects/dataview/buffer/index.md | 2 +- .../global_objects/dataview/bytelength/index.md | 2 +- .../global_objects/dataview/byteoffset/index.md | 2 +- .../global_objects/date/getdate/index.md | 2 +- .../global_objects/date/getday/index.md | 2 +- .../global_objects/date/getfullyear/index.md | 2 +- .../global_objects/date/gethours/index.md | 2 +- .../date/getmilliseconds/index.md | 2 +- .../global_objects/date/getminutes/index.md | 2 +- .../global_objects/date/getmonth/index.md | 2 +- .../global_objects/date/getseconds/index.md | 2 +- .../global_objects/date/gettime/index.md | 2 +- .../global_objects/date/getutcdate/index.md | 2 +- .../global_objects/date/getutcday/index.md | 2 +- .../global_objects/date/getutcfullyear/index.md | 2 +- .../global_objects/date/getutchours/index.md | 2 +- .../date/getutcmilliseconds/index.md | 2 +- .../global_objects/date/getutcminutes/index.md | 2 +- .../global_objects/date/getutcmonth/index.md | 2 +- .../global_objects/date/getutcseconds/index.md | 2 +- .../global_objects/date/parse/index.md | 14 ++------------ .../global_objects/date/setdate/index.md | 2 +- .../global_objects/date/setfullyear/index.md | 2 +- .../global_objects/date/sethours/index.md | 2 +- .../date/setmilliseconds/index.md | 2 +- .../global_objects/date/setminutes/index.md | 2 +- .../global_objects/date/setmonth/index.md | 2 +- .../global_objects/date/setseconds/index.md | 2 +- .../global_objects/date/settime/index.md | 2 +- .../global_objects/date/setutchours/index.md | 2 +- .../date/setutcmilliseconds/index.md | 2 +- .../global_objects/date/setyear/index.md | 2 +- .../global_objects/date/todatestring/index.md | 2 +- .../global_objects/date/toisostring/index.md | 2 +- .../global_objects/date/totimestring/index.md | 2 +- .../global_objects/date/toutcstring/index.md | 2 +- .../global_objects/date/valueof/index.md | 2 +- .../global_objects/decodeuricomponent/index.md | 2 +- .../reference/global_objects/encodeuri/index.md | 2 +- .../global_objects/error/columnnumber/index.md | 2 +- .../global_objects/error/filename/index.md | 2 +- .../global_objects/error/message/index.md | 2 +- .../global_objects/error/name/index.md | 2 +- .../global_objects/generator/return/index.md | 9 +++++---- .../global_objects/generator/throw/index.md | 4 ++-- .../reference/global_objects/int8array/index.md | 6 ++++-- .../intl/numberformat/format/index.md | 2 +- .../reference/global_objects/isfinite/index.md | 2 +- .../reference/global_objects/isnan/index.md | 2 +- .../reference/global_objects/json/index.md | 2 +- .../global_objects/json/stringify/index.md | 4 ++-- .../reference/global_objects/math/acos/index.md | 3 +-- .../reference/global_objects/math/asin/index.md | 3 +-- .../global_objects/math/asinh/index.md | 3 ++- .../reference/global_objects/math/atan/index.md | 3 +-- .../global_objects/math/atan2/index.md | 3 +-- .../global_objects/math/atanh/index.md | 2 +- .../global_objects/math/clz32/index.md | 2 +- .../reference/global_objects/math/cos/index.md | 11 ++++++++--- .../reference/global_objects/math/cosh/index.md | 15 ++++++++------- .../reference/global_objects/math/e/index.md | 6 ++++-- .../reference/global_objects/math/exp/index.md | 9 ++++++--- .../global_objects/math/fround/index.md | 2 +- .../global_objects/math/hypot/index.md | 2 +- .../reference/global_objects/math/ln10/index.md | 6 ++++-- .../reference/global_objects/math/ln2/index.md | 6 ++++-- .../reference/global_objects/math/log/index.md | 6 ++++-- .../global_objects/math/log10/index.md | 11 ++++++++--- .../global_objects/math/log10e/index.md | 6 ++++-- .../global_objects/math/log1p/index.md | 14 ++++++++++---- .../reference/global_objects/math/log2/index.md | 11 ++++++++--- .../global_objects/math/log2e/index.md | 6 ++++-- .../reference/global_objects/math/pi/index.md | 4 ++-- .../reference/global_objects/math/pow/index.md | 4 ++-- .../global_objects/math/random/index.md | 4 ++-- .../global_objects/math/round/index.md | 2 +- .../reference/global_objects/math/sign/index.md | 11 ++++++++--- .../reference/global_objects/math/sin/index.md | 2 +- .../reference/global_objects/math/sinh/index.md | 2 +- .../global_objects/math/sqrt1_2/index.md | 5 +++-- .../global_objects/math/sqrt2/index.md | 5 +++-- .../global_objects/math/trunc/index.md | 3 ++- .../global_objects/parsefloat/index.md | 4 ++-- .../reference/global_objects/parseint/index.md | 2 +- .../proxy/getownpropertydescriptor/index.md | 2 +- .../global_objects/proxy/proxy/index.md | 8 ++++---- .../reflect/defineproperty/index.md | 2 +- .../reflect/deleteproperty/index.md | 6 ++++-- .../global_objects/reflect/get/index.md | 2 +- .../reflect/getownpropertydescriptor/index.md | 2 +- .../reflect/getprototypeof/index.md | 2 +- .../reference/global_objects/reflect/index.md | 5 ++--- .../reflect/isextensible/index.md | 2 +- .../global_objects/reflect/ownkeys/index.md | 2 +- .../reflect/preventextensions/index.md | 2 +- .../global_objects/reflect/set/index.md | 2 +- .../reflect/setprototypeof/index.md | 2 +- .../global_objects/regexp/@@matchall/index.md | 2 +- .../global_objects/regexp/compile/index.md | 2 +- .../global_objects/regexp/dotall/index.md | 2 +- .../global_objects/regexp/global/index.md | 7 +++++-- .../global_objects/regexp/ignorecase/index.md | 2 +- .../reference/global_objects/regexp/index.md | 13 ++++++++----- .../global_objects/regexp/lastindex/index.md | 2 +- .../global_objects/regexp/multiline/index.md | 2 +- .../global_objects/regexp/source/index.md | 2 +- .../global_objects/regexp/sticky/index.md | 2 +- .../global_objects/regexp/test/index.md | 4 ++-- .../global_objects/regexp/tostring/index.md | 2 +- .../sharedarraybuffer/bytelength/index.md | 2 +- .../sharedarraybuffer/slice/index.md | 2 +- .../global_objects/string/repeat/index.md | 2 +- .../global_objects/symbol/for/index.md | 2 +- .../global_objects/symbol/keyfor/index.md | 2 +- .../global_objects/symbol/match/index.md | 2 +- .../global_objects/symbol/species/index.md | 2 +- .../global_objects/symbol/tostring/index.md | 2 +- .../global_objects/symbol/unscopables/index.md | 4 ++-- .../global_objects/symbol/valueof/index.md | 2 +- .../global_objects/typedarray/tostring/index.md | 2 +- .../global_objects/uint32array/index.md | 4 ++-- .../reference/global_objects/unescape/index.md | 8 ++++---- .../global_objects/weakref/deref/index.md | 2 +- .../reference/global_objects/weakref/index.md | 2 +- 139 files changed, 270 insertions(+), 232 deletions(-) diff --git a/files/zh-cn/web/javascript/reference/classes/static/index.md b/files/zh-cn/web/javascript/reference/classes/static/index.md index 0961f9546388e1..c32cfb025b2d98 100644 --- a/files/zh-cn/web/javascript/reference/classes/static/index.md +++ b/files/zh-cn/web/javascript/reference/classes/static/index.md @@ -97,8 +97,8 @@ console.log(tp.tripple()); // 'tp.tripple 不是一个函数'. {{Compat}} -## 相关链接 +## 参见 -- [`class`表达式](/zh-CN/docs/Web/JavaScript/Reference/Operators/class) -- [`class`声明](/zh-CN/docs/Web/JavaScript/Reference/Statements/class) -- [Classes](/zh-CN/docs/Web/JavaScript/Reference/Classes) +- [`class` 表达式](/zh-CN/docs/Web/JavaScript/Reference/Operators/class) +- [`class` 声明](/zh-CN/docs/Web/JavaScript/Reference/Statements/class) +- [类](/zh-CN/docs/Web/JavaScript/Reference/Classes) diff --git a/files/zh-cn/web/javascript/reference/errors/index.md b/files/zh-cn/web/javascript/reference/errors/index.md index b8ede1101ec9a1..e2c3245f5ccf78 100644 --- a/files/zh-cn/web/javascript/reference/errors/index.md +++ b/files/zh-cn/web/javascript/reference/errors/index.md @@ -14,7 +14,3 @@ Web 控制台中显示的错误可能包含指向下面相应页面的链接, 在此列表中,每个页面按名称(错误类型)和信息(更详细的容易理解的错误信息)列出。总之,这两者提供了理解和解决错误的线索。有关更多信息,请按照以下链接! {{ListSubPages("/zh-CN/docs/Web/JavaScript/Reference/Errors")}} - -## 相关链接 - -- [What went wrong? Troubleshooting JavaScript](/zh-CN/docs/Learn/JavaScript/First_steps/What_went_wrong): Beginner's introductory tutorial on fixing JavaScript errors. diff --git a/files/zh-cn/web/javascript/reference/errors/json_bad_parse/index.md b/files/zh-cn/web/javascript/reference/errors/json_bad_parse/index.md index 1f3b06343f4e8a..f5d0a2c3c5a2d7 100644 --- a/files/zh-cn/web/javascript/reference/errors/json_bad_parse/index.md +++ b/files/zh-cn/web/javascript/reference/errors/json_bad_parse/index.md @@ -106,7 +106,7 @@ JSON.parse('{"foo" : 1 }'); JSON.parse('{"foo" : 1.0 }'); ``` -## 相关链接 +## 参见 - {{jsxref("JSON")}} - {{jsxref("JSON.parse()")}} diff --git a/files/zh-cn/web/javascript/reference/errors/not_a_constructor/index.md b/files/zh-cn/web/javascript/reference/errors/not_a_constructor/index.md index 653fd8d49098c2..bf020b4a3582a3 100644 --- a/files/zh-cn/web/javascript/reference/errors/not_a_constructor/index.md +++ b/files/zh-cn/web/javascript/reference/errors/not_a_constructor/index.md @@ -92,7 +92,7 @@ return Promise.resolve(true); return Promise.reject(false); ``` -## 相关链接 +## 参见 - {{Glossary("constructor")}} -- [`new` operator](/zh-CN/docs/Web/JavaScript/Reference/Operators/new) +- [`new` 运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/new) diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/index.md b/files/zh-cn/web/javascript/reference/functions/arguments/index.md index cc76409aeb20c2..f0d6606ebf2a54 100644 --- a/files/zh-cn/web/javascript/reference/functions/arguments/index.md +++ b/files/zh-cn/web/javascript/reference/functions/arguments/index.md @@ -234,6 +234,6 @@ func(); // undefined {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Function")}} diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/length/index.md b/files/zh-cn/web/javascript/reference/functions/arguments/length/index.md index 4444b93bb770fa..e009457f72c170 100644 --- a/files/zh-cn/web/javascript/reference/functions/arguments/length/index.md +++ b/files/zh-cn/web/javascript/reference/functions/arguments/length/index.md @@ -33,7 +33,7 @@ function adder(base /*, n2, ... */) { } ``` -## Specifications +## 规范 {{Specifications}} @@ -41,6 +41,6 @@ function adder(base /*, n2, ... */) { {{Compat}} -## 相关链接 +## 参见 - [Function.length](/zh-CN/docs/JavaScript/Reference/Global_Objects/Function/length) diff --git a/files/zh-cn/web/javascript/reference/functions/arrow_functions/index.md b/files/zh-cn/web/javascript/reference/functions/arrow_functions/index.md index 0bfe23d2ae79d1..0f24e81fc4eb6e 100644 --- a/files/zh-cn/web/javascript/reference/functions/arrow_functions/index.md +++ b/files/zh-cn/web/javascript/reference/functions/arrow_functions/index.md @@ -481,6 +481,6 @@ fact(5); // 120 {{Compat}} -## 相关链接 +## 参见 - ["ES6 In Depth: Arrow functions" on hacks.mozilla.org](https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/) diff --git a/files/zh-cn/web/javascript/reference/functions/default_parameters/index.md b/files/zh-cn/web/javascript/reference/functions/default_parameters/index.md index 783934087612e4..fb7baf835e15e9 100644 --- a/files/zh-cn/web/javascript/reference/functions/default_parameters/index.md +++ b/files/zh-cn/web/javascript/reference/functions/default_parameters/index.md @@ -213,6 +213,9 @@ f(); // 6 {{Compat}} -## 相关链接 +## 参见 -- [Original proposal at ecmascript.org](http://wiki.ecmascript.org/doku.php?id=harmony:parameter_default_values) +- [函数](/zh-CN/docs/Web/JavaScript/Guide/Functions)指南 +- [函数](/zh-CN/docs/Web/JavaScript/Reference/Functions)参考 +- [剩余参数](/zh-CN/docs/Web/JavaScript/Reference/Functions/rest_parameters) +- [空值合并运算符(`??`)](/zh-CN/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing) diff --git a/files/zh-cn/web/javascript/reference/functions/get/index.md b/files/zh-cn/web/javascript/reference/functions/get/index.md index e0f6a1f498e9a1..31b88f97b29eb5 100644 --- a/files/zh-cn/web/javascript/reference/functions/get/index.md +++ b/files/zh-cn/web/javascript/reference/functions/get/index.md @@ -150,7 +150,7 @@ console.log( {{Compat}} -## 相关链接 +## 参见 - [setter](/zh-CN/docs/Web/JavaScript/Reference/Functions/set) - {{jsxref("Operators/delete", "delete")}} diff --git a/files/zh-cn/web/javascript/reference/functions/rest_parameters/index.md b/files/zh-cn/web/javascript/reference/functions/rest_parameters/index.md index 3e721c5712f50a..8f7fcaa04a2cac 100644 --- a/files/zh-cn/web/javascript/reference/functions/rest_parameters/index.md +++ b/files/zh-cn/web/javascript/reference/functions/rest_parameters/index.md @@ -137,12 +137,11 @@ console.log(sortArguments(5, 3, 7, 1)); // shows 1, 3, 5, 7 {{Compat}} -## 相关链接 - -- [Spread operator](/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_operator) (also ‘`...`’) -- [Arguments object](/zh-CN/docs/Web/JavaScript/Reference/Functions/arguments) -- [Array](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array) -- [Functions](/zh-CN/docs/Web/JavaScript/Reference/Functions) -- [Original proposal at ecmascript.org](http://wiki.ecmascript.org/doku.php?id=harmony:rest_parameters) -- [JavaScript arguments object and beyond](http://javascriptweblog.wordpress.com/2011/01/18/javascripts-arguments-object-and-beyond/) -- [Destructuring assignment](/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) +## 参见 + +- [函数](/zh-CN/docs/Web/JavaScript/Guide/Functions)指南 +- [函数](/zh-CN/docs/Web/JavaScript/Reference/Functions)参考 +- [展开语法(`...`)](/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax) +- [默认参数](/zh-CN/docs/Web/JavaScript/Reference/Functions/Default_parameters) +- {{jsxref("Functions/arguments", "arguments")}} +- {{jsxref("Array")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/slice/index.md b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/slice/index.md index ca23db25690f49..817ad9a691bdf0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/slice/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/slice/index.md @@ -47,6 +47,6 @@ var buf2 = buf1.slice(0); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("ArrayBuffer")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/store/index.md b/files/zh-cn/web/javascript/reference/global_objects/atomics/store/index.md index 03e1c1c7f212b6..83a757bcf1be90 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/atomics/store/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/store/index.md @@ -51,7 +51,7 @@ Atomics.store(ta, 0, 12); // 12 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Atomics")}} - {{jsxref("Atomics.load()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/bigint/index.md b/files/zh-cn/web/javascript/reference/global_objects/bigint/bigint/index.md index 97c3f54398b070..cae8b72f547624 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/bigint/bigint/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/bigint/index.md @@ -9,8 +9,8 @@ slug: Web/JavaScript/Reference/Global_Objects/BigInt/BigInt ## 语法 -```plain -BigInt(value); +```js-nolint +BigInt(value) ``` ### 参数 @@ -35,6 +35,6 @@ BigInt(123); {{Compat}} -## 相关链接 +## 参见 -- {{jsxref("BigInt")}} class +- {{jsxref("BigInt")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/index.md b/files/zh-cn/web/javascript/reference/global_objects/bigint/index.md index 844968967eebb3..af1637ab1cfc2f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/bigint/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/index.md @@ -251,16 +251,14 @@ nthPrime(20n); // ↪ 73n ``` -## 标准 +## 规范 -| 标准 | 状态 | -| ------------------------------------------------------------- | --------- | -| [BigInt](https://tc39.es/proposal-bigint/#sec-bigint-objects) | 第 4 阶段 | +{{Specifications}} ## 浏览器兼容性 {{Compat}} -## 相关链接 +## 参见 - {{JSxRef("Number")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/boolean/valueof/index.md b/files/zh-cn/web/javascript/reference/global_objects/boolean/valueof/index.md index e8237a77242fc7..afc1f5a813876d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/boolean/valueof/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/boolean/valueof/index.md @@ -42,6 +42,6 @@ myVar = x.valueOf(); // assigns false to myVar {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Object.prototype.valueOf()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.md b/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.md index e4d7cc4de165d2..3daceefc189ad2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.md @@ -37,7 +37,7 @@ dataview.buffer; // ArrayBuffer { byteLength: 8 } {{Compat}} -## 相关链接 +## 参见 - {{jsxref("DataView")}} - {{jsxref("ArrayBuffer")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.md b/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.md index e2ae71f8929f5f..9e7197904c691a 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.md @@ -43,7 +43,7 @@ dataview3.byteLength; // 6 (due to the offset of the constructed DataView) {{Compat}} -## 相关链接 +## 参见 - {{jsxref("DataView")}} - {{jsxref("ArrayBuffer")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.md b/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.md index 70c4a08426c9a6..7c0a862fb6618d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.md @@ -40,7 +40,7 @@ dataview2.byteOffset; // 3 (在构造 DataView 时指定) {{Compat}} -## 相关链接 +## 参见 - {{jsxref("DataView")}} - {{jsxref("ArrayBuffer")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.md index df6d361641b7ca..a117f8efc7fabf 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.md @@ -44,7 +44,7 @@ alert(day); // 25 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCDate()")}} - {{jsxref("Date.prototype.getUTCDay()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.md index 598a74b4804f6e..97b9051d70fad2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.md @@ -50,7 +50,7 @@ console.log(weekday); // 1 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCDate()")}} - {{jsxref("Date.prototype.getUTCDay()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.md index b92e2a616f36c7..9303b437db6b45 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.md @@ -44,7 +44,7 @@ var year = today.getFullYear(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCFullYear()")}} - {{jsxref("Date.prototype.setFullYear()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.md index ecea3556113b1b..9444009eefdd88 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.md @@ -44,7 +44,7 @@ alert(hours); // 23 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCHours()")}} - {{jsxref("Date.prototype.setHours()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.md index 9f4ac77f9c3044..2dfc9a02da04aa 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.md @@ -43,7 +43,7 @@ ms = Today.getMilliseconds(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCMilliseconds()")}} - {{jsxref("Date.prototype.setMilliseconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.md index 92ea23561d6e6f..59701e2cc541e2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.md @@ -42,7 +42,7 @@ var minutes = Xmas95.getMinutes(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCMinutes()")}} - {{jsxref("Date.prototype.setMinutes()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.md index b943aa39e47f52..6da43e092012b9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.md @@ -44,7 +44,7 @@ console.log(month); // 11 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCMonth()")}} - {{jsxref("Date.prototype.setMonth()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.md index 889fa08953ffec..a9066f00d56d52 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.md @@ -42,7 +42,7 @@ var secs = Xmas95.getSeconds(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCSeconds()")}} - {{jsxref("Date.prototype.setSeconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gettime/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/gettime/index.md index bf5b687a4ce3c9..1eec9928bed1e0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gettime/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gettime/index.md @@ -61,7 +61,7 @@ console.log("Operation took " + (end.getTime() - start.getTime()) + " msec"); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.setTime()")}} - {{jsxref("Date.prototype.valueOf()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcdate/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcdate/index.md index 4913fa12540be3..18f6c5010a2f31 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcdate/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcdate/index.md @@ -42,7 +42,7 @@ var day = today.getUTCDate(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getDate()")}} - {{jsxref("Date.prototype.getUTCDay()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcday/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcday/index.md index 05cbad3290baf6..c41d77b9b0d341 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcday/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcday/index.md @@ -42,7 +42,7 @@ var weekday = today.getUTCDay(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCDate()")}} - {{jsxref("Date.prototype.getDay()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcfullyear/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcfullyear/index.md index 0d4f43f139804d..fccf47a6d0c605 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcfullyear/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcfullyear/index.md @@ -42,7 +42,7 @@ var year = today.getUTCFullYear(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getFullYear()")}} - {{jsxref("Date.prototype.setFullYear()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutchours/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutchours/index.md index d3f4013d18c76e..1d081684db7792 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutchours/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutchours/index.md @@ -42,7 +42,7 @@ var hours = today.getUTCHours(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getHours()")}} - {{jsxref("Date.prototype.setUTCHours()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcmilliseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcmilliseconds/index.md index eafde5ff4fc433..e0fc2603c88076 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcmilliseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcmilliseconds/index.md @@ -42,7 +42,7 @@ var milliseconds = today.getUTCMilliseconds(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMilliseconds()")}} - {{jsxref("Date.prototype.setUTCMilliseconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcminutes/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcminutes/index.md index c460847d3ef4aa..8439eea60efda5 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcminutes/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcminutes/index.md @@ -42,7 +42,7 @@ var minutes = today.getUTCMinutes(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMinutes()")}} - {{jsxref("Date.prototype.setUTCMinutes()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcmonth/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcmonth/index.md index 65975982a99f36..4403b16b625022 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcmonth/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcmonth/index.md @@ -42,7 +42,7 @@ var month = today.getUTCMonth(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMonth()")}} - {{jsxref("Date.prototype.setUTCMonth()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getutcseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/getutcseconds/index.md index 6d1a77d9ec52ed..7e9cde561b58b3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getutcseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getutcseconds/index.md @@ -42,7 +42,7 @@ var seconds = today.getUTCSeconds(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getSeconds()")}} - {{jsxref("Date.prototype.setUTCSeconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.md index 5d354d67f1ca28..4d092199774429 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.md @@ -15,16 +15,10 @@ slug: Web/JavaScript/Reference/Global_Objects/Date/parse 显式调用: -```plain +```js-nolint Date.parse(dateString) ``` -`隐式调用:` - -```plain -new Date(dateString).getTime() -``` - ### 参数 - `dateString` @@ -147,10 +141,6 @@ Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400"); {{Compat}} -## 兼容性提示 - -Firefox 49 修改了解析 2 位数年份的方式,从和 Internet Explorer 一致改为和 Google Chrome 浏览器一致。现在,2 位数的年份小于等于 `50` 的将会被解析为 21 世纪的年份。比如,`04/16/17`,在之前会被解析为 1917 年 4 月 16 日,现在将被解析为 2017 年 4 月 16 日。为了避免任何可能的同步问题或者有歧义的年份,推荐使用 ISO 8601 格式如 "2017-04-16" ([Firefox bug 1265136](https://bugzil.la/1265136))。 - -## 相关链接 +## 参见 - {{jsxref("Date.UTC()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setdate/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setdate/index.md index 85528723245f69..46df56e90ac989 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setdate/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setdate/index.md @@ -46,7 +46,7 @@ theBigDay.setDate(32); // 1962-08-01 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getDate()")}} - {{jsxref("Date.prototype.setUTCDate()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.md index 87c8ea03d26db1..0b7ddbeae003e9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.md @@ -47,7 +47,7 @@ theBigDay.setFullYear(1997); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCFullYear()")}} - {{jsxref("Date.prototype.setUTCFullYear()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.md index 383ff89bc9886d..9d84eda4b83ef9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.md @@ -55,7 +55,7 @@ theBigDay.setHours(7); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getHours()")}} - {{jsxref("Date.prototype.setUTCHours()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setmilliseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setmilliseconds/index.md index 8925757293840a..da2e0575dbb523 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setmilliseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setmilliseconds/index.md @@ -41,7 +41,7 @@ theBigDay.setMilliseconds(100); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMilliseconds()")}} - {{jsxref("Date.prototype.setUTCMilliseconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setminutes/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setminutes/index.md index 9db4f7de273020..ed6be1104ae15b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setminutes/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setminutes/index.md @@ -53,7 +53,7 @@ theBigDay.setMinutes(45); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMinutes()")}} - {{jsxref("Date.prototype.setUTCMinutes()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.md index 7590f6ee7be156..d1c45a29d3a661 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.md @@ -53,7 +53,7 @@ theBigDay.setMonth(6); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getMonth()")}} - {{jsxref("Date.prototype.setUTCMonth()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setseconds/index.md index 383143db5e6c6b..7d72cd1d5b8c97 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setseconds/index.md @@ -51,7 +51,7 @@ theBigDay.setSeconds(30); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getSeconds()")}} - {{jsxref("Date.prototype.setUTCSeconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/settime/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/settime/index.md index 85c037e9edd072..c8cba9f15e0d4b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/settime/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/settime/index.md @@ -46,7 +46,7 @@ sameAsBigDay.setTime(theBigDay.getTime()); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getTime()")}} - {{jsxref("Date.prototype.setUTCHours()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.md index e1451ca01361d9..8770d8bcadb338 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.md @@ -53,7 +53,7 @@ theBigDay.setUTCHours(8); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCHours()")}} - {{jsxref("Date.prototype.setHours()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setutcmilliseconds/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setutcmilliseconds/index.md index 7b1c9729aa9d7c..a720df711c9daf 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setutcmilliseconds/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setutcmilliseconds/index.md @@ -45,7 +45,7 @@ theBigDay.setUTCMilliseconds(500); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getUTCMilliseconds()")}} - {{jsxref("Date.prototype.setMilliseconds()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.md index 6fabd9cb8341a8..a3085b1769c6d9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.md @@ -48,7 +48,7 @@ theBigDay.setYear(2000); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.getFullYear()")}} - {{jsxref("Date.prototype.getUTCFullYear()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.md index 363acde2872143..4925bc558d9c94 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.md @@ -40,7 +40,7 @@ println(d.toDateString()); // prints Wed Jul 28 1993 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.toLocaleDateString()")}} - {{jsxref("Date.prototype.toTimeString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/toisostring/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/toisostring/index.md index 0fe7dd96df6019..94b7fa62ee5c4b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/toisostring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/toisostring/index.md @@ -68,7 +68,7 @@ if (!Date.prototype.toISOString) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.toLocaleDateString()")}} - {{jsxref("Date.prototype.toTimeString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.md index 5134f94a854ff8..9afce74bf35d36 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.md @@ -40,7 +40,7 @@ println(d.toTimeString()); // prints 14:39:07 GMT-0600 (PDT) {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.toLocaleTimeString()")}} - {{jsxref("Date.prototype.toDateString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/toutcstring/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/toutcstring/index.md index ac985e41f571b2..7267a406d10460 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/toutcstring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/toutcstring/index.md @@ -41,7 +41,7 @@ var UTCstring = today.toUTCString(); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.toLocaleString()")}} - {{jsxref("Date.prototype.toDateString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/valueof/index.md b/files/zh-cn/web/javascript/reference/global_objects/date/valueof/index.md index 8f8b102fdb8f66..a128863ba2f527 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/valueof/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/date/valueof/index.md @@ -44,7 +44,7 @@ var myVar = x.valueOf(); // assigns -424713600000 to myVar {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Object.prototype.valueOf()")}} - {{jsxref("Date.prototype.getTime()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.md b/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.md index 82244ae3cf9628..7804ea7fe8bc12 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.md @@ -59,7 +59,7 @@ try { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("decodeURI")}} - {{jsxref("encodeURI")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/encodeuri/index.md b/files/zh-cn/web/javascript/reference/global_objects/encodeuri/index.md index 6182bd44d2e238..47d6eac28b9991 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/encodeuri/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/encodeuri/index.md @@ -69,7 +69,7 @@ function fixedEncodeURI(str) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("decodeURI")}} - {{jsxref("encodeURIComponent")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/columnnumber/index.md b/files/zh-cn/web/javascript/reference/global_objects/error/columnnumber/index.md index f685a6948bacb0..dc072a0ef8fd2f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/columnnumber/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/error/columnnumber/index.md @@ -25,7 +25,7 @@ console.log(e.columnNumber); // 0 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Error.prototype.stack")}} {{non-standard_inline}} - {{jsxref("Error.prototype.lineNumber")}} {{non-standard_inline}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/filename/index.md b/files/zh-cn/web/javascript/reference/global_objects/error/filename/index.md index 61e24f3137d29e..00f34cc4eea57f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/filename/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/error/filename/index.md @@ -29,7 +29,7 @@ throw e; {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Error.prototype.stack")}} {{non-standard_inline}} - {{jsxref("Error.prototype.columnNumber")}} {{non-standard_inline}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/message/index.md b/files/zh-cn/web/javascript/reference/global_objects/error/message/index.md index 4f8105701435e8..d21ca62f7b9c41 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/message/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/error/message/index.md @@ -32,7 +32,7 @@ throw e; {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Error.prototype.name")}} - {{jsxref("Error.prototype.toString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.md b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.md index 20a77e54ed0a4c..3aba5a623faffc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.md @@ -32,7 +32,7 @@ throw e; // "ParseError: Malformed input" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Error.prototype.message")}} - {{jsxref("Error.prototype.toString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/generator/return/index.md b/files/zh-cn/web/javascript/reference/global_objects/generator/return/index.md index 426cad819e3b21..e3cfaca15b51f5 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/generator/return/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/generator/return/index.md @@ -9,8 +9,9 @@ slug: Web/JavaScript/Reference/Global_Objects/Generator/return ## 语法 -```plain -gen.return(value) +```js-nolint +generatorInstance.return() +generatorInstance.return(value) ``` ### 参数 @@ -68,6 +69,6 @@ g.return(1); // { value: 1, done: true } {{Compat}} -## 相关链接 +## 参见 -- [`function*`](/zh-CN/docs/Web/JavaScript/Reference/Statements/function*) +- {{jsxref("Statements/function*", "function*")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.md b/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.md index 1428eebe2f69a9..82517a84b10ac9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.md @@ -59,6 +59,6 @@ g.throw(new Error("Something went wrong")); // "Error caught!" {{Compat}} -## 相关链接 +## 参见 -- [`function*`](/zh-CN/docs/Web/JavaScript/Reference/Statements/function*) +- {{jsxref("Statements/function*", "function*")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/int8array/index.md b/files/zh-cn/web/javascript/reference/global_objects/int8array/index.md index a9846446ba33eb..9a83d53769a1d6 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/int8array/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/int8array/index.md @@ -154,8 +154,10 @@ var dv = Int8Array([1, 2, 3]); var dv = new Int8Array([1, 2, 3]); ``` -## 相关链接 +## 参见 -- [JavaScript typed arrays](/zh-CN/docs/Web/JavaScript/Typed_arrays) +- [`core-js` 中 `Int8Array` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-typed-arrays) +- [JavaScript 类型化数组](/zh-CN/docs/Web/JavaScript/Typed_arrays)指南 +- {{jsxref("TypedArray")}} - {{jsxref("ArrayBuffer")}} - {{jsxref("DataView")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/intl/numberformat/format/index.md b/files/zh-cn/web/javascript/reference/global_objects/intl/numberformat/format/index.md index 90d8d2392c231b..3aeb04b1b8847b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/intl/numberformat/format/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/intl/numberformat/format/index.md @@ -57,7 +57,7 @@ console.log(formatted.join("; ")); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("NumberFormat", "Intl.NumberFormat")}} - {{jsxref("Number.prototype.toLocaleString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.md b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.md index dbbed1523cbb4e..ca3922f4d490cd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.md @@ -47,7 +47,7 @@ isFinite("0"); // true,在更强壮的 Number.isFinite('0') 中将会得到 fa {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Number.isFinite()")}} - {{jsxref("Number.NaN()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.md b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.md index ffed96efca82bb..e12a2441ab276b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.md @@ -155,7 +155,7 @@ isNaN() == isNaN(Number()); // false, because isNaN() == true and Number() == 0 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("NaN")}} - {{jsxref("Number.isNaN()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/json/index.md b/files/zh-cn/web/javascript/reference/global_objects/json/index.md index a077a2d6dee79f..c48a9d97fce32f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/json/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/json/index.md @@ -184,6 +184,6 @@ if (!window.JSON) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Date.prototype.toJSON()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/json/stringify/index.md b/files/zh-cn/web/javascript/reference/global_objects/json/stringify/index.md index 11a23b780930eb..8fdbeba121d412 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/json/stringify/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/json/stringify/index.md @@ -250,7 +250,7 @@ console.log(restoredSession); {{Compat}} -## 相关链接 +## 参见 +- [`core-js` 中对现代 `JSON.stringify` 行为(符号和良好格式的 unicode)的 polyfill](https://github.com/zloirock/core-js#ecmascript-json) - {{JSxRef("JSON.parse()")}} -- [cycle.js](https://github.com/douglascrockford/JSON-js/blob/master/cycle.js) – Introduces two functions: `JSON.decycle` and `JSON.retrocycle`. These allow encoding and decoding of cyclical structures and DAGs into an extended and retrocompatible JSON format. diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/acos/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/acos/index.md index 84ae253948d988..ecf9d05b6a54a4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/acos/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/acos/index.md @@ -51,9 +51,8 @@ Math.acos(2); // NaN {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.asin()")}} - {{jsxref("Math.atan()")}} - {{jsxref("Math.atan2()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/asin/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/asin/index.md index 77984461808291..e428f689f3dfb9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/asin/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/asin/index.md @@ -51,9 +51,8 @@ Math.asin(2); // NaN {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.acos()")}} - {{jsxref("Math.atan()")}} - {{jsxref("Math.atan2()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/asinh/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/asinh/index.md index 7c48fcf80c2bc5..4adae070ee0e88 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/asinh/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/asinh/index.md @@ -65,8 +65,9 @@ Been formally correct it suffers from a number of issues related to floating poi {{Compat}} -## 相关链接 +## 参见 +- [`core-js` 中 `Math.asinh` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) - {{jsxref("Math.acosh()")}} - {{jsxref("Math.atanh()")}} - {{jsxref("Math.cosh()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/atan/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/atan/index.md index 92d94f0cd695ae..dfb58abb8e6840 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/atan/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/atan/index.md @@ -45,9 +45,8 @@ Math.atan(0); // 0 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.acos()")}} - {{jsxref("Math.asin()")}} - {{jsxref("Math.atan2()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/atan2/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/atan2/index.md index 63a8938c785eae..319c76d12f2e71 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/atan2/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/atan2/index.md @@ -57,9 +57,8 @@ Math.atan2( ±Infinity, +Infinity ) // ±PI/4. {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.acos()")}} - {{jsxref("Math.asin()")}} - {{jsxref("Math.atan()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/atanh/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/atanh/index.md index bedf650d350351..f04fefc956795c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/atanh/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/atanh/index.md @@ -59,7 +59,7 @@ Math.atanh = {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.acosh()")}} - {{jsxref("Math.asinh()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.md index 3232733888740c..09d72a22014dfa 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.md @@ -173,7 +173,7 @@ if (!Math.clz32) {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math")}} - {{jsxref("Math.imul")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/cos/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/cos/index.md index 7d826eb528f55f..2dcb05641c6a25 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/cos/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/cos/index.md @@ -46,6 +46,11 @@ Math.cos(2 * Math.PI); // 1 {{Compat}} -## 相关链接 - -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +## 参见 + +- {{jsxref("Math.acos()")}} +- {{jsxref("Math.asin()")}} +- {{jsxref("Math.atan()")}} +- {{jsxref("Math.atan2()")}} +- {{jsxref("Math.sin()")}} +- {{jsxref("Math.tan()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/cosh/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/cosh/index.md index 019a0476afaebb..bd663d3ee356a0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/cosh/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/cosh/index.md @@ -65,10 +65,11 @@ Math.cosh = {{Compat}} -## 相关链接 - -- {{jsxref("Math.acosh()")}} {{experimental_inline}} -- {{jsxref("Math.asinh()")}} {{experimental_inline}} -- {{jsxref("Math.atanh()")}} {{experimental_inline}} -- {{jsxref("Math.sinh()")}} {{experimental_inline}} -- {{jsxref("Math.tanh()")}} {{experimental_inline}} +## 参见 + +- [`core-js` 中 `Math.cosh` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) +- {{jsxref("Math.acosh()")}} +- {{jsxref("Math.asinh()")}} +- {{jsxref("Math.atanh()")}} +- {{jsxref("Math.sinh()")}} +- {{jsxref("Math.tanh()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/e/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/e/index.md index 7f29421e7489fa..84bdc4ca1f91be 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/e/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/e/index.md @@ -39,6 +39,8 @@ getNapier(); // 2.718281828459045 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log1p()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/exp/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/exp/index.md index 050d1e4ab4e4b0..ca76bd014677ee 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/exp/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/exp/index.md @@ -11,7 +11,7 @@ slug: Web/JavaScript/Reference/Global_Objects/Math/exp ## 语法 -```plain +```js-nolint Math.exp(x) ``` @@ -42,9 +42,12 @@ Math.exp(1); // 2.718281828459045 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.E")}} +- {{jsxref("Math.expm1()")}} - {{jsxref("Math.log()")}} +- {{jsxref("Math.log10()")}} +- {{jsxref("Math.log1p()")}} +- {{jsxref("Math.log2()")}} - {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/fround/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/fround/index.md index 144276f061e444..d27718c13d6888 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/fround/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/fround/index.md @@ -98,6 +98,6 @@ Math.fround = {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.round()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/hypot/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/hypot/index.md index 2475a72c9f7ece..dc81fd330bb2ff 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/hypot/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/hypot/index.md @@ -98,7 +98,7 @@ if (!Math.hypot) {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.abs()")}} - {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/ln10/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/ln10/index.md index 71d512347666dc..b8355c48cf83da 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/ln10/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/ln10/index.md @@ -39,6 +39,8 @@ getNatLog10(); // 2.302585092994046 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log10()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/ln2/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/ln2/index.md index c1e3f8b10d6d68..62a875c2217786 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/ln2/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/ln2/index.md @@ -39,6 +39,8 @@ getNatLog2(); // 0.6931471805599453 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log2()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log/index.md index c8aa3d0dd12d45..1eea4f00b45f2d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log/index.md @@ -61,8 +61,10 @@ function getBaseLog(x, y) { {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. - {{jsxref("Math.exp()")}} +- {{jsxref("Math.log1p()")}} +- {{jsxref("Math.log10()")}} +- {{jsxref("Math.log2()")}} - {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.md index 5e3eeb8c2846e9..16425107c597c7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.md @@ -44,6 +44,11 @@ Math.log10("foo"); // NaN {{Compat}} -## 相关链接 - -- {{jsxref("Global_Objects/Math", "Math")}} 对象。 +## 参见 + +- [`core-js` 中 `Math.log10` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log1p()")}} +- {{jsxref("Math.log2()")}} +- {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log10e/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log10e/index.md index aa9b6e42084bd2..b55a4470d4b18e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log10e/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log10e/index.md @@ -39,6 +39,8 @@ getLog10e(); // 0.4342944819032518 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log10()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.md index 725855d112b81c..0a640008a81c90 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.md @@ -11,7 +11,7 @@ slug: Web/JavaScript/Reference/Global_Objects/Math/log1p ## 语法 -```plain +```js-nolint Math.log1p(x) ``` @@ -22,7 +22,7 @@ Math.log1p(x) ## 描述 -如果参数的值小于`-1`, 则返回 `NaN.` +如果参数的值小于 `-1`,则返回 `NaN`。 函数 `y = log(x+1)` 的图形是这样的: @@ -47,6 +47,12 @@ Math.log1p("foo"); // NaN {{Compat}} -## 相关链接 +## 参见 -- {{jsxref("Global_Objects/Math", "Math")}} 对象。 +- [`core-js` 中 `Math.log1p` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.expm1()")}} +- {{jsxref("Math.log10()")}} +- {{jsxref("Math.log2()")}} +- {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log2/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log2/index.md index 436c9be1758730..a7d03787628d6b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log2/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log2/index.md @@ -44,6 +44,11 @@ Math.log2("foo"); // NaN {{Compat}} -## 相关链接 - -- {{jsxref("Global_Objects/Math", "Math")}} 对象。 +## 参见 + +- [`core-js` 中 `Math.log2` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log10()")}} +- {{jsxref("Math.log1p()")}} +- {{jsxref("Math.pow()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log2e/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/log2e/index.md index 6aa418d4a57309..d1cef094274f08 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log2e/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log2e/index.md @@ -39,6 +39,8 @@ getLog2e(); // 1.4426950408889634 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.exp()")}} +- {{jsxref("Math.log()")}} +- {{jsxref("Math.log2()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.md index c375362fbbf975..d31480615165d2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.md @@ -39,6 +39,6 @@ calculateCircumference(1); // 6.283185307179586 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.md index 969dde09de8c44..449b23ce37bc39 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.md @@ -46,10 +46,10 @@ function raisePower(x, y) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.cbrt()")}} - {{jsxref("Math.exp()")}} - {{jsxref("Math.log()")}} - {{jsxref("Math.sqrt()")}} -- [Exponentiation operator](/zh-CN/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation) {{experimental_inline}} +- [乘方(`**`)](/zh-CN/docs/Web/JavaScript/Reference/Operators/Exponentiation) diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.md index b5150c1161ff73..0a86b0792a1142 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.md @@ -75,6 +75,6 @@ function getRandomIntInclusive(min, max) { {{Compat}} -## 相关链接 +## 参见 -- [`window.crypto.getRandomValues()`](/zh-CN/docs/Web/API/RandomSource/getRandomValues) +- {{domxref("Crypto/getRandomValues", "window.crypto.getRandomValues()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/round/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/round/index.md index 9d9997c4094235..c39415025d1548 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/round/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/round/index.md @@ -131,7 +131,7 @@ round(1.005, 2); //1.01 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.abs()")}} - {{jsxref("Math.ceil()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.md index 99cda4f339faa7..b8bdd450fffd78 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.md @@ -78,6 +78,11 @@ if (!Math.sign) { {{Compat}} -## 相关链接 - -- {{jsxref("Global_Objects/Math", "Math")}} 对象 +## 参见 + +- [`core-js` 中 `Math.sign` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) +- {{jsxref("Math.abs()")}} +- {{jsxref("Math.ceil()")}} +- {{jsxref("Math.floor()")}} +- {{jsxref("Math.round()")}} +- {{jsxref("Math.trunc()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sin/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/sin/index.md index 1a05d02c9abff6..80e170cf09ca95 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sin/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sin/index.md @@ -45,7 +45,7 @@ Math.sin(Math.PI / 2); // 1 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.acos()")}} - {{jsxref("Math.asin()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sinh/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/sinh/index.md index ca9c3823379209..4a5d2388d91dab 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sinh/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sinh/index.md @@ -53,7 +53,7 @@ function sinh(x) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Math.acos()")}} - {{jsxref("Math.asin()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt1_2/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt1_2/index.md index 23d7b4de445a2e..7ceb1ac3e62c59 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt1_2/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt1_2/index.md @@ -39,6 +39,7 @@ getRoot1_2(); // 0.7071067811865476 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.pow()")}} +- {{jsxref("Math.sqrt()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.md index 1924603f01f32f..79e5f6910b1c66 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.md @@ -35,6 +35,7 @@ getRoot2(); // 1.4142135623730951 {{Compat}} -## 相关链接 +## 参见 -- The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to. +- {{jsxref("Math.pow()")}} +- {{jsxref("Math.sqrt()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.md b/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.md index d3292ea21f0864..288f237da10276 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.md @@ -87,8 +87,9 @@ if (!Math.trunc) { {{Compat}} -**相关链接** +## 参见 +- [`core-js` 中 `Math.trunc` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-math) - {{jsxref("Math.abs()")}} - {{jsxref("Math.ceil()")}} - {{jsxref("Math.floor()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.md b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.md index df7398dbb7ac03..e9c161a8ce8edc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.md @@ -11,7 +11,7 @@ slug: Web/JavaScript/Reference/Global_Objects/parseFloat ## 语法 -```plain +```js-nolint parseFloat(string) ``` @@ -84,7 +84,7 @@ parseFloat("900719925474099267n"); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Global_Objects/parseInt", "parseInt()")}} - {{jsxref("Number.parseFloat()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.md b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.md index f9efcb2921b93f..0c80cc1c9fe414 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.md @@ -170,7 +170,7 @@ console.log(filterInt("1.61803398875")); // NaN {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} - {{jsxref("Number.parseFloat()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/getownpropertydescriptor/index.md b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/getownpropertydescriptor/index.md index 324e6ee72be087..3c06966bed2317 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/getownpropertydescriptor/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/getownpropertydescriptor/index.md @@ -90,7 +90,7 @@ Object.getOwnPropertyDescriptor(p, "a"); // TypeError is thrown {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Proxy")}} - {{jsxref("Proxy.handler", "handler")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/index.md b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/index.md index 8dc91137464296..a340140dad6a4f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/index.md @@ -7,7 +7,7 @@ slug: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy ## 语法 -```plain +```js-nolint new Proxy(target, handler) ``` @@ -93,7 +93,7 @@ console.log(proxy.proxied); // "replaced value" {{Compat}} -## 相关链接 +## 参见 -- [`Proxy` and `Reflect` in the JavaScript Guide](/zh-CN/docs/Web/JavaScript/Guide/Meta_programming) -- {{jsxref("Global_Objects/Reflect", "Reflect")}} +- [元编程](/zh-CN/docs/Web/JavaScript/Guide/Meta_programming)指南 +- {{jsxref("Reflect")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/defineproperty/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/defineproperty/index.md index 96a2613f63fe50..35bc7b03a02fb0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/defineproperty/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/defineproperty/index.md @@ -66,7 +66,7 @@ if (Reflect.defineProperty(target, property, attributes)) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.defineProperty()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/deleteproperty/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/deleteproperty/index.md index ffc74d349b6673..21e7bf3e16484f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/deleteproperty/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/deleteproperty/index.md @@ -60,7 +60,9 @@ Reflect.deleteProperty(Object.freeze({ foo: 1 }), "foo"); // false {{Compat}} -## 相关链接 +## 参见 +- [`core-js` 中 `Reflect.deleteProperty` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-reflect) - {{jsxref("Reflect")}} -- [`delete` operator](/zh-CN/docs/Web/JavaScript/Reference/Operators/delete) +- [`delete`](/zh-CN/docs/Web/JavaScript/Reference/Operators/delete) +- [`handler.deleteProperty()`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/deleteProperty) diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/get/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/get/index.md index 41d56aba49133f..cb5510fe69af54 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/get/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/get/index.md @@ -64,7 +64,7 @@ Reflect.get(obj, "foo"); // "foobar" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - [属性访问器](/zh-CN/docs/Web/JavaScript/Reference/Operators/Property_accessors) diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/getownpropertydescriptor/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/getownpropertydescriptor/index.md index 8c9f17543284ef..ea03a69feb8c87 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/getownpropertydescriptor/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/getownpropertydescriptor/index.md @@ -67,7 +67,7 @@ Object.getOwnPropertyDescriptor("foo", 0); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.getOwnPropertyDescriptor()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/getprototypeof/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/getprototypeof/index.md index 57c2d81c4a7489..7b3efabade023e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/getprototypeof/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/getprototypeof/index.md @@ -69,7 +69,7 @@ Reflect.getPrototypeOf(Object('foo')) // String.prototype {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.getPrototypeOf()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/index.md index 53b52baa0f86c2..7d6c095c306397 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/index.md @@ -84,7 +84,6 @@ Reflect.set(duck, 'eyes', 'black'); {{Compat}} -## 相关链接 +## 参见 -- {{jsxref("Proxy")}} 全局对象。 -- {{jsxref("Proxy.handler", "处理器")}} 对象。 +- {{jsxref("Proxy")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/isextensible/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/isextensible/index.md index c172516e9771f9..1c1ad3e8ce5fd4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/isextensible/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/isextensible/index.md @@ -74,7 +74,7 @@ Object.isExtensible(1); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.isExtensible()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/ownkeys/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/ownkeys/index.md index a380eb21450a16..80d735b2876594 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/ownkeys/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/ownkeys/index.md @@ -67,7 +67,7 @@ Reflect.ownKeys(obj); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.getOwnPropertyNames()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.md index 44e499e8c82fe6..07e1e59062a1bf 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.md @@ -68,7 +68,7 @@ Object.preventExtensions(1); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.isExtensible()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/set/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/set/index.md index 4c5738cdf9c20e..e0f91473b7598b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/set/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/set/index.md @@ -70,7 +70,7 @@ Reflect.getOwnPropertyDescriptor(obj, "undefined"); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - [属性访问器](/zh-CN/docs/Web/JavaScript/Reference/Operators/Property_accessors) diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/setprototypeof/index.md b/files/zh-cn/web/javascript/reference/global_objects/reflect/setprototypeof/index.md index 9b0af550548478..06af925d8f7c03 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/setprototypeof/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/setprototypeof/index.md @@ -61,7 +61,7 @@ Reflect.setPrototypeOf(target, proto); // false {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Reflect")}} - {{jsxref("Object.setPrototypeOf()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.md index e60f6617ca5b1c..bf58afa73f5eff 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.md @@ -78,7 +78,7 @@ console.log(result[1]); // [ "2019-03-07", "2019", "03", "07" ] {{Compat}} -## 相关链接 +## 参见 - {{JSxRef("String.prototype.matchAll()")}} - {{JSxRef("Symbol.matchAll")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.md index 2171d60e81b688..6e0fd9411b7f21 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.md @@ -53,6 +53,6 @@ regexObj.compile("new foo", "g"); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.md index a6aa7afc68f9ca..77bc9a6affe1c1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.md @@ -26,7 +26,7 @@ slug: Web/JavaScript/Reference/Global_Objects/RegExp/dotAll {{Compat}} -## 相关链接 +## 参见 - {{JSxRef("RegExp.lastIndex")}} - {{JSxRef("RegExp.prototype.global")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/global/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/global/index.md index 4eea7f45ba1226..0e9c5d41c70655 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/global/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/global/index.md @@ -35,10 +35,13 @@ console.log(regex.global); // true {{Compat}} -## 相关链接 +## 参见 -- {{jsxref("RegExp.prototype.ignoreCase")}} - {{jsxref("RegExp.prototype.lastIndex")}} +- {{jsxref("RegExp.prototype.dotAll")}} +- {{jsxref("RegExp.prototype.hasIndices")}} +- {{jsxref("RegExp.prototype.ignoreCase")}} - {{jsxref("RegExp.prototype.multiline")}} - {{jsxref("RegExp.prototype.source")}} - {{jsxref("RegExp.prototype.sticky")}} +- {{jsxref("RegExp.prototype.unicode")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/ignorecase/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/ignorecase/index.md index c5ad32ca7c43ef..5bd84d034b3dca 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/ignorecase/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/ignorecase/index.md @@ -35,7 +35,7 @@ console.log(regex.ignoreCase); // true {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp.prototype.global")}} - {{jsxref("RegExp.prototype.lastIndex")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.md index 229cde611f8b6e..8ea2a99f66d63d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.md @@ -216,8 +216,11 @@ console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx" {{Compat}} -## 相关链接 - -- [JavaScript 指南](/zh-CN/docs/Web/JavaScript/Guide)中的[正则表达式](/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions)一节 -- [String.prototype.match()](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/match) -- [String.prototype.replace()](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replace) +## 参见 + +- [`core-js` 中很多现代 `RegExp` 特性(`dotAll`、`sticky` 标志、具名捕获组等)的 polyfill](https://github.com/zloirock/core-js#ecmascript-string-and-regexp) +- [正则表达式](/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions)指南 +- [正则表达式](/zh-CN/docs/Web/JavaScript/Reference/Regular_expressions)参考 +- {{jsxref("String.prototype.match()")}} +- {{jsxref("String.prototype.replace()")}} +- {{jsxref("String.prototype.split()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.md index 2c9d735fac0a03..b76ad435fe4527 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.md @@ -59,7 +59,7 @@ console.log(re.lastIndex); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp.prototype.ignoreCase")}} - {{jsxref("RegExp.prototype.global")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/multiline/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/multiline/index.md index d5ef8580327f62..9d27cc1a9e5552 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/multiline/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/multiline/index.md @@ -35,7 +35,7 @@ console.log(regex.multiline); // true {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp.prototype.global")}} - {{jsxref("RegExp.prototype.lastIndex")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/source/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/source/index.md index dd2ebd7d63ce63..c9caf2b55999c3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/source/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/source/index.md @@ -25,6 +25,6 @@ console.log(regex.source); // "fooBar",不包含 /.../ 和 "ig"。 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp.prototype.flags")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.md index 336ca6a5d35280..f0fc2f39a4aa65 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.md @@ -60,7 +60,7 @@ regex2.test(".\nfoo"); // true - 索引 2 是行的开始 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("RegExp.lastIndex")}} - {{jsxref("RegExp.prototype.global")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/test/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/test/index.md index 55fca2add81627..8dd551e1cd64d2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/test/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/test/index.md @@ -79,7 +79,7 @@ regex.test("foo"); // false {{Compat}} -## 相关链接 +## 参见 -- 在[JavaScript 指南](/zh-CN/docs/Web/JavaScript/Guide)的[正则表达式](/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions)章节 +- [JavaScript 指南](/zh-CN/docs/Web/JavaScript/Guide)的[正则表达式](/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions)章节 - {{jsxref("RegExp")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/tostring/index.md b/files/zh-cn/web/javascript/reference/global_objects/regexp/tostring/index.md index da23e2c30b124f..65e8fd2de11e18 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/tostring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/tostring/index.md @@ -45,6 +45,6 @@ alert(foo.toString()); // 显示 "/bar/g" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Object.prototype.toString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/bytelength/index.md b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/bytelength/index.md index eb320638354f8b..006e2627522530 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/bytelength/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/bytelength/index.md @@ -32,6 +32,6 @@ sab.byteLength; // 1024 {{Compat}} -## 相关链接 +## 参见 - {{jsxref("SharedArrayBuffer")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.md b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.md index 749293fa10b5c1..f63d7857a2ff81 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.md @@ -46,7 +46,7 @@ sab.slice(0, 1); // SharedArrayBuffer { byteLength: 1 } {{Compat}} -## 相关链接 +## 参见 - {{jsxref("SharedArrayBuffer")}} - {{jsxref("Array.prototype.slice()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.md b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.md index 7a4af8c1d79aed..8217af1d9b5f5e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.md @@ -53,7 +53,7 @@ repeat(count) {{Compat}} -## 相关链接 +## 参见 - [`core-js` 中 `String.prototype.repeat` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-string-and-regexp) - {{jsxref("String.prototype.concat()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/for/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/for/index.md index c47b9fda660143..dd6dd851829138 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/for/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/for/index.md @@ -64,6 +64,6 @@ Symbol.for("mdn.bar"); {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Symbol.keyFor()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/keyfor/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/keyfor/index.md index b27fa86ceedd7c..29eab3e392fe28 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/keyfor/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/keyfor/index.md @@ -46,6 +46,6 @@ Symbol.keyFor(Symbol.iterator); // undefined {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Symbol.prototype.for()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/match/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/match/index.md index 497b9e9b397d98..46da3abb8cc323 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/match/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/match/index.md @@ -45,7 +45,7 @@ re[Symbol.match] = false; {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Symbol.replace")}} - {{jsxref("Symbol.search")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/species/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/species/index.md index a7823b4dabc69a..9b0aaf18222cbb 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/species/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/species/index.md @@ -39,7 +39,7 @@ console.log(mapped instanceof Array); // true {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Map.@@species", "Map[@@species]")}} - {{jsxref("Set.@@species", "Set[@@species]")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/tostring/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/tostring/index.md index 39886c4c8eefd6..982f40771045dd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/tostring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/tostring/index.md @@ -52,6 +52,6 @@ Symbol.for("foo").toString(); // "Symbol(foo)" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Object.prototype.toString()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/unscopables/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/unscopables/index.md index b71d9f1285cbd9..aa9fce30046ac7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/unscopables/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/unscopables/index.md @@ -60,7 +60,7 @@ with (obj) { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Array.@@unscopables", "Array.prototype[@@unscopables]")}} -- [`with`](/zh-CN/docs/Web/JavaScript/Reference/Statements/with) statement (not available in [Strict mode](/zh-CN/docs/Web/JavaScript/Reference/Strict_mode)) +- [`with`](/zh-CN/docs/Web/JavaScript/Reference/Statements/with) 语句(在[严格模式](/zh-CN/docs/Web/JavaScript/Reference/Strict_mode)中不可用) diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/valueof/index.md b/files/zh-cn/web/javascript/reference/global_objects/symbol/valueof/index.md index 9bbf00050b0f20..44a8ca168a7747 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/valueof/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/valueof/index.md @@ -40,6 +40,6 @@ Object(Symbol("foo")).toString() + "bar"; {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Object.prototype.valueOf()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/typedarray/tostring/index.md b/files/zh-cn/web/javascript/reference/global_objects/typedarray/tostring/index.md index a38115f7806e5b..781e5852ee8f6f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/typedarray/tostring/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/typedarray/tostring/index.md @@ -45,6 +45,6 @@ numbers.toString(); // "[object Uint8Array]" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("TypedArray.prototype.join()")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/uint32array/index.md b/files/zh-cn/web/javascript/reference/global_objects/uint32array/index.md index 459ca246c948b8..36219b0ca2e067 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/uint32array/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/uint32array/index.md @@ -148,8 +148,8 @@ var uint32 = new Uint32Array(iterable); {{Compat}} -## 相关链接 +## 参见 -- [JavaScript typed arrays](/zh-CN/docs/Web/JavaScript/Typed_arrays) +- [JavaScript 类型化数组](/zh-CN/docs/Web/JavaScript/Guide/Typed_arrays) - {{jsxref("ArrayBuffer")}} - {{jsxref("DataView")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/unescape/index.md b/files/zh-cn/web/javascript/reference/global_objects/unescape/index.md index b68be9bc37a741..efa014527395df 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/unescape/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/unescape/index.md @@ -3,15 +3,15 @@ title: unescape() slug: Web/JavaScript/Reference/Global_Objects/unescape --- -{{jsSidebar("Objects")}} +{{jsSidebar("Objects")}}{{Deprecated_Header}} 已废弃的**`unescape()`** 方法计算生成一个新的字符串,其中的十六进制转义序列将被其表示的字符替换。上述的转义序列就像{{jsxref("escape")}}里介绍的一样。因为 `unescape` 已经废弃,建议使用 {{jsxref("decodeURI")}}或者{{jsxref("decodeURIComponent")}} 替代本方法。 -> **备注:** 不要使用`unescape`去解码 URLS,使用`decodeURI`或`decodeURIComponent`替代。 +> **备注:** 不要使用 `unescape` 去解码 URL,请使用 {{jsxref("decodeURI()")}} 或 {{jsxref("decodeURIComponent()")}} 替代。 ## 语法 -```plain +```js-nolint unescape(str) ``` @@ -44,7 +44,7 @@ unescape("%u0107"); // "ć" {{Compat}} -## 相关链接 +## 参见 - {{jsxref("decodeURI")}} - {{jsxref("decodeURIComponent")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.md b/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.md index 98ab7a889cb792..b768ff8f4eedb4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.md @@ -48,6 +48,6 @@ const tick = () => { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("WeakRef")}} diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakref/index.md b/files/zh-cn/web/javascript/reference/global_objects/weakref/index.md index a4a94079dd2c34..770e6273b54d80 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/weakref/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/weakref/index.md @@ -109,7 +109,7 @@ setTimeout(() => { {{Compat}} -## 相关链接 +## 参见 - {{jsxref("FinalizationRegistry")}} - {{jsxref("WeakSet")}} From 3a2f2157b0b1e78455cd7eb889719c7357042100 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:55:42 +0800 Subject: [PATCH 3/4] [zh-cn] update 'working with the history api' (#17063) Co-authored-by: A1lo --- .../working_with_the_history_api/index.md | 195 +++++++++++++----- 1 file changed, 141 insertions(+), 54 deletions(-) diff --git a/files/zh-cn/web/api/history_api/working_with_the_history_api/index.md b/files/zh-cn/web/api/history_api/working_with_the_history_api/index.md index 8375f748c2f446..bf693cb6dbc7e2 100644 --- a/files/zh-cn/web/api/history_api/working_with_the_history_api/index.md +++ b/files/zh-cn/web/api/history_api/working_with_the_history_api/index.md @@ -1,105 +1,192 @@ --- title: 使用历史记录 API slug: Web/API/History_API/Working_with_the_History_API +l10n: + sourceCommit: 56bbf2804abdfdbf9ad93386ba4c956196d06a37 --- {{DefaultAPISidebar("History API")}} -{{DOMxRef("History.pushState", "pushState()")}} 和 {{DOMxRef("History.replaceState", "replaceState()")}} 方法分别添加和修改历史条目。这些方法与 {{domxref("Window/popstate_event", "popstate")}} 事件一起工作。 +历史记录 API 使网站能够与浏览器的会话历史记录(即用户在给定窗口中访问过的页面列表)进行交互。当用户通过点击链接等方式访问新页面时,这些新页面就会被添加到会话历史记录中。用户还可以使用浏览器的“后退”和“前进”按钮在历史记录中来回移动。 -## 添加和修改历史记录 +历史记录 API 中定义的主要接口是 {{domxref("History")}} 接口,它定义了两套截然不同的方法: -使用 {{DOMxRef("History.pushState", "pushState()")}} 可以改变在你改变状态后创建的 {{domxref("XMLHttpRequest")}} 对象的 HTTP 标头中使用的 referrer。referrer 将是创建 {{domxref("XMLHttpRequest")}} 对象时其窗口为 `this` 的文档的 URL。 +1. 在会话历史记录中导航到页面的方法: -### pushState() 方法示例 + - {{domxref("History.back()")}} + - {{domxref("History.forward()")}} + - {{domxref("History.go()")}} -假设 `https://mozilla.org/foo.html` 执行下面的 JavaScript: +2. 修改会话历史记录的方法: -```js -const stateObj = { - foo: "bar", -}; - -history.pushState(stateObj, "page 2", "bar.html"); -``` + - {{domxref("History.pushState()")}} + - {{domxref("History.replaceState()")}} -这将导致地址栏显示 `https://mozilla.org/bar.html`,但不会导致浏览器加载 `bar.html` 或甚至检查 `bar.html` 是否存在。 +在本指南中,我们将只关注第二组方法,因为这些方法的行为更为复杂。 -假设现在用户导航到 `https://google.com`,然后点击了**返回**按钮。这时,地址栏将显示 `https://mozilla.org/bar.html`,`history.state` 将包含 `stateObj`。`popstate` 事件将不会被触发,因为页面已经被重新加载。页面本身将看起来像 `bar.html`。 +`pushState()` 方法会向会话历史记录添加新条目,而 `replaceState()` 方法则会更新当前页面的会话历史记录条目。这两种方法都接收一个 `state` 参数,该参数可包含任何{{Glossary("Serializable_object", "可序列化对象")}}。当浏览器导航到该历史条目时,浏览器会触发 {{domxref("Window.popstate_event", "popstate")}} 事件,其中包含与该条目相关的状态对象。 -如果用户再次点击**返回**,URL 将变为 `https://mozilla.org/foo.html`,并且文档将得到一个 `popstate` 事件,这次是一个 `null` 状态对象。在这里,返回也不会改变文档的内容,尽管文档在收到 `popstate` 事件后可能会手动更新其内容。 +这些 API 的主要目的是支持像{{Glossary("SPA", "单页应用")}}这样的网站,它们使用 JavaScript API(如 {{domxref("fetch()")}})来更新页面的新内容,而不是加载整个新页面。 -### pushState() 方法 +## 单页应用和会话历史记录 -`pushState()` 需要三个参数:一个**状态对象**;一个**标题**(目前忽略);以及一个(可选)**URL**。 +传统上,网站是以页面集合的形式实现的。当用户通过点击链接浏览网站的不同部分时,浏览器每次都会加载一个全新的页面。 -让我们详细地解释一下这三个参数 +虽然这对许多网站来说很好,但也有一些缺点: -- **状态对象** - - : 状态对象是一个 JavaScript 对象,它与由 `pushState()` 创建的新历史条目相关。每当用户浏览到新的状态时,一个 `popstate` 事件被触发,该事件的 `state` 属性包含历史条目的状态对象的副本。状态对象可以是任何可以被序列化的东西。因为 Firefox 将状态对象保存在用户的磁盘上,以便在用户重新启动浏览器后恢复,所以我们对状态对象的序列化表示法规定了 640k 字符的大小限制。如果你传递给 `pushState()` 的状态对象的序列化表示大于这个大小,该方法将抛出一个异常。如果你需要比这更多的空间,我们鼓励你使用 `sessionStorage` 和/或 `localStorage`。 -- **标题** - - : [除了 Safari,所有的浏览器目前都忽略了这个参数](https://github.com/whatwg/html/issues/2174),尽管它们在未来可能会使用这个参数。在这里传递空字符串应该是安全的,可以避免将来对该方法的修改。另外,你也可以为你要移动的状态传入一个简短的标题。 -- **URL** - - : 新的历史条目的 URL 是由这个参数给出的。注意,在调用 `pushState()` 后,浏览器不会尝试加载这个 URL,但它可能会在以后尝试加载这个 URL,例如在用户重新启动浏览器后。新的 URL 不需要是绝对的;如果它是相对的,它就会相对于当前的 URL 进行解析。新的 URL 必须与当前的 URL 同源;否则,`pushState()` 将抛出一个异常。这个参数是可选的;如果没有指定它,它将被设置为文档的当前 URL。 +- 如果只需要更新页面的一部分,每次加载整个页面的效率会很低。 +- 跨页面导航时很难保持应用程序状态 -在某种意义上,调用 `pushState()` 类似于设置 `window.location = "#foo"`,因为两者都将创建并激活与当前文档相关的另一个历史条目。 +由于这些原因,{{Glossary("SPA", "单页应用")}}(SPA)是一种流行的 web 应用程序模式,在这种模式中,网站由一个页面组成,当用户点击链接时,页面会: -但是 `pushState()` 有几条优势: +1. 阻止加载新页面的默认行为 +2. {{domxref("fetch()", "获取", "", "nocode")}}要显示的新内容 +3. 用新内容更新页面 -- 新的 URL 可以是与当前 URL 同源的任何 URL。相比之下,只有当你只修改锚点值时,设置 `window.location` 使你保持在同一个 {{ domxref("document") }}。 -- 如果你不愿意,你不必改变 URL。相反,设置 `window.location = "#foo";` 只在当前锚点值不是 `#foo` 的情况下创建一个新的历史条目。 -- 你可以将任意的数据与你的新历史条目联系起来。使用基于哈希的方法,你需要将所有的相关数据编码成一个短字符串。 -- 如果 `title` 随后被浏览器使用,这个数据可以被利用(而锚点值会独立于每个历史条目)。 +例如: -请注意,`pushState()` 永远不会触发 `hashchange` 事件,即使新的 URL 与旧的 URL 只在锚点值上有所不同。 +```js +document.addEventListener("click", async (event) => { + const creature = event.target.getAttribute("data-creature"); + if (creature) { + // 阻止新页面加载 + event.preventDefault(); + try { + // 获取新内容 + const response = await fetch(`creatures/${creature}.json`); + const json = await response.json(); + // 用新内容更新页面 + displayContent(json); + } catch (err) { + console.error(err); + } + } +}); +``` -在其他文档中,它创建了一个具有 `null` 命名空间 URI 的元素。 +在该单击处理器中,如果链接包含数据属性 `"data-creature"`,我们就会使用该属性的值来获取包含页面新内容的 JSON 文件。 -### replaceState() 方法 +JSON 文件可能如下所示: -`history.replaceState()` 的操作与 `history.pushState()` 完全一样,只是 `replaceState()` 修改了当前的历史条目,而不是创建一个新的。注意,这并不妨碍在全局浏览器历史中创建一个新条目。 +```json +{ + "description": "Bald eagles are not actually bald.", + "image": { + "src": "images/eagle.jpg", + "alt": "A bald eagle" + }, + "name": "Eagle" +} +``` -`replaceState()` 在你想更新当前历史条目的状态对象或 URL 以响应某些用户操作时特别有用。 +`displayContent()` 函数使用 JSON 内容更新页面: -### replaceState() 方法示例 +```js +// 使用新内容更新页面 +function displayContent(content) { + document.title = `生物:${content.name}`; -假设 `https://mozilla.org/foo.html` 执行了下列 JavaScript 代码: + const description = document.querySelector("#description"); + description.textContent = content.description; -```js -const stateObj = { - foo: "bar", -}; -history.pushState(stateObj, "page 2", "bar.html"); + const photo = document.querySelector("#photo"); + photo.setAttribute("src", content.image.src); + photo.setAttribute("alt", content.image.alt); +} ``` -上面这两行的解释可以在上面的 [_pushState() 方法的例子_](#pushstate_方法示例)部分找到。 +问题在于,它破坏了浏览器“后退”和“前进”按钮的预期行为。 + +从用户的角度来看,他们点击了一个链接,页面就更新了,所以看起来像是一个新页面。如果用户按下浏览器的“后退”按钮,就会返回到点击链接之前的状态。 + +但在浏览器看来,最后一个链接并没有加载新页面,因此“后退”按钮会将浏览器带回到用户打开 SPA 之前加载的页面。 + +这正是 `pushState()`、`replaceState()` 和 `popstate` 事件所要解决的问题。它们使我们能够合成历史条目,并在当前会话历史条目更改为这些条目之一(例如,由于用户按下了“后退”或“前进”按钮)时收到通知。 -然后,假设 `https://mozilla.org/bar.html` 执行了下列 JavaScript 代码: +## 使用 `pushState()` + +我们可以像下面这样在单击事件处理器中添加历史记录条目: ```js -history.replaceState(stateObj, "page 3", "bar2.html"); +document.addEventListener("click", async (event) => { + const creature = event.target.getAttribute("data-creature"); + if (creature) { + event.preventDefault(); + try { + const response = await fetch(`creatures/${creature}.json`); + const json = await response.json(); + displayContent(json); + // 向历史记录中添加新条目 + // 模拟了新页面的加载 + history.pushState(json, "", creature); + } catch (err) { + console.error(err); + } + } +}); ``` -这将导致 URL 栏显示 `https://mozilla.org/bar2.html`,但不会导致浏览器加载 `bar2.html` 或甚至检查 `bar2.html` 是否存在。 +这里,我们使用三个参数调用了 `pushState()`: + +- `json`:这是我们刚刚获取的内容。它将与历史条目一起存储,之后将作为 {{domxref("PopStateEvent.state", "state")}} 属性包含在传递给 `popstate` 事件处理器的参数中。 +- `""`:这是与传统网站向后兼容所必需的,应始终为空字符串。 +- `creature`:这将用作条目的 URL。它将显示在浏览器的 URL 栏中,并在页面发出的任何 HTTP 请求中用作 {{httpheader("Referer")}} 标头的值。请注意,这必须与页面{{Glossary("Same-origin policy", "同源")}} 。 + +## 使用 `popstate` 事件 -假设现在用户导航到 `https://www.microsoft.com`,然后点击**返回**按钮。此时,URL 栏将显示 `https://mozilla.org/bar2.html`。如果用户现在再次点击**返回**,URL 栏将显示`https://mozilla.org/foo.html`,完全绕过了 `bar.html`。 +假设用户: -### popstate 事件 +1. 点击了 SPA 中的一个链接,因此我们使用 `pushState()` 更新页面并添加历史记录条目 A +2. 点击 SPA 中的另一个链接,因此我们使用 `pushState()` 更新页面并添加历史记录条目 B +3. 按下“后退”按钮 + +现在,新的当前历史记录条目是 A,因此浏览器触发了 `popstate` 事件,事件处理器参数包括我们在处理导航到 A 时传递给 `pushState()` 的 JSON,这意味着我们可以通过这样的事件处理器来恢复正确的内容: + +```js +// 处理前进/回退按钮 +window.addEventListener("popstate", (event) => { + // 如果提供了一个状态(state),我们“模拟”一个页面并更新当前页面 + if (event.state) { + // 模拟前一个页面加载 + displayContent(event.state); + } +}); +``` -每次活动的历史条目发生变化时,都会向窗口派发一个 `popstate` 事件。如果被激活的历史条目是通过调用 {{DOMxRef("History.pushState", "pushState")}} 创建的,或通过调用 {{DOMxRef("History.replaceState", "replaceState")}} 影响的,`popstate` 事件的 `state` 属性包含历史条目的状态对象副本。 +## 使用 `replaceState()` -请参阅 {{domxref("Window/popstate_event", "popstate")}} 了解使用示例。 +我们还需要添加一项内容。当用户加载 SPA 时,浏览器会添加一个历史记录条目。由于这是一次实际的页面加载,因此该条目没有与之相关的状态。因此,假设用户: -### 读取当前状态 +1. 加载 SPA:浏览器添加历史记录条目 +2. 点击 SPA 中的一个链接:点击处理程序会更新页面,并使用 `pushState()` 添加一个历史记录条目 +3. 按下“后退”按钮 -当你的页面加载时,它可能有一个非空的状态对象。例如,如果页面设置了一个状态对象(使用 {{DOMxRef("History.pushState", "pushState()")}} 或 {{DOMxRef("History.replaceState", "replaceState()")}}),然后用户重新启动他们的浏览器,这种情况就会发生。当页面重新加载时,该页面将收到一个 `onload` 事件,但没有 `popstate` 事件。然而,如果你读取 {{DOMxRef("History.state", "history.state")}} 属性,你会重新得到 `popstate` 事件发生时应该得到的状态对象。 +现在我们想回到 SPA 的初始状态,但由于这是同一文档中的导航,页面不会被重新加载,而且初始页面的历史条目没有状态,我们无法使用 `popstate` 恢复它。 -你可以使用 {{DOMxRef("History.state", "history.state")}} 属性读取当前历史条目的状态,而不需要等待 `popstate` 事件,像这样: +解决办法是使用 `replaceState()` 为初始页面设置状态对象。例如: ```js -const currentState = history.state; +// 在页面加载时创建状态,并用其替换当前历史记录 +const image = document.querySelector("#photo"); +const initialState = { + description: document.querySelector("#description").textContent, + image: { + src: image.getAttribute("src"), + alt: image.getAttribute("alt"), + }, + name: "Home", +}; +history.replaceState(initialState, "", document.location.href); ``` +在页面加载时,我们会收集页面的所有部分,以便在用户返回 SPA 的起点时还原这些部分。这与我们在处理其他导航时获取的 JSON 结构相同。我们将这个 `initialState` 对象传递给 `replaceState()`,这样就能有效地将状态对象添加到当前历史记录条目中。 + +当用户返回到我们的起点时,`popstate` 事件将包含此初始状态,我们可以使用 `displayContent()` 函数更新页面。 + +## 一个完整的示例 + +你可以在 中看到完整的示例,并在 访问到实时运行的版本。 + ## 参见 - [历史记录 API](/zh-CN/docs/Web/API/History_API) From 5a632d39cdacc4ed0cbad3eae4dab6909df3cafb Mon Sep 17 00:00:00 2001 From: Fina <42113148+BSPR0002@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:02:59 +0800 Subject: [PATCH 4/4] [zh-cn]: improve 'html examples guidelines' (#17037) --- .../writing_style_guide/code_style_guide/html/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/zh-cn/mdn/writing_guidelines/writing_style_guide/code_style_guide/html/index.md b/files/zh-cn/mdn/writing_guidelines/writing_style_guide/code_style_guide/html/index.md index db0aebb19d29a9..8bd4ce9168d353 100644 --- a/files/zh-cn/mdn/writing_guidelines/writing_style_guide/code_style_guide/html/index.md +++ b/files/zh-cn/mdn/writing_guidelines/writing_style_guide/code_style_guide/html/index.md @@ -61,7 +61,7 @@ Prettier 格式化所有代码并保持风格一致。尽管如此,你仍需 ## 属性 -你应该把所有的属性值放在双引号之间。自从 HTML5 允许省略引号后,人们很轻易地就会这样做,但是添加引号能让标记更加简洁和易读。例如,这样就比较好: +你应该把所有的属性值放在双引号之间。自从 HTML5 允许省略引号后,人们会很轻易地省略引号,但是添加引号能让标记更加简洁和易读。例如,这样就比较好: ```html example-good A circular globe icon @@ -103,7 +103,7 @@ Prettier 格式化所有代码并保持风格一致。尽管如此,你仍需 ## Class 和 ID 名称 -使用语义化的 class/ID 名称,并且使用连字符分隔多个单词({{Glossary("kebab_case", "短横线命名法")}})。不要使用{{Glossary("camel_case", "骆驼式命名法")}}。例如: +使用语义化的 class/ID 名称,并且使用连字符分隔多个单词({{Glossary("kebab_case", "短横线命名法")}})。不要使用{{Glossary("camel_case", "驼峰式命名法")}}。例如: ```html example-good

其他内容