From d44f5032d0f53256b2d5aef505d6b593fd3cd158 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:14:18 +0800 Subject: fix yari h2m dry run errors (zh-CN) --- .../reference/functions/arguments/index.html | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/functions/arguments/index.html') diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/index.html b/files/zh-cn/web/javascript/reference/functions/arguments/index.html index 8b708b2c37..db796d1651 100644 --- a/files/zh-cn/web/javascript/reference/functions/arguments/index.html +++ b/files/zh-cn/web/javascript/reference/functions/arguments/index.html @@ -21,12 +21,12 @@ translation_of: Web/JavaScript/Reference/Functions/arguments

描述

-
-

Note: If you're writing ES6 compatible code, then rest parameters should be preferred.

+
+

备注: If you're writing ES6 compatible code, then rest parameters should be preferred.

-
-

Note: “Array-like” means that arguments has a {{jsxref("Functions/arguments/length", "length")}} property and properties indexed from zero, but it doesn't have {{JSxRef("Array")}}'s built-in methods like {{jsxref("Array.forEach", "forEach()")}} and {{jsxref("Array.map", "map()")}}. See §Description for details.

+
+

备注: “Array-like” means that arguments has a {{jsxref("Functions/arguments/length", "length")}} property and properties indexed from zero, but it doesn't have {{JSxRef("Array")}}'s built-in methods like {{jsxref("Array.forEach", "forEach()")}} and {{jsxref("Array.map", "map()")}}. See §Description for details.

arguments对象是所有(非箭头)函数中都可用的局部变量。你可以使用arguments对象在函数中引用函数的参数。此对象包含传递给函数的每个参数,第一个参数在索引0处。例如,如果一个函数传递了三个参数,你可以以如下方式引用他们:

@@ -51,7 +51,7 @@ const args = [...arguments];
-

对参数使用slice会阻止某些JavaScript引擎中的优化 (比如 V8 - 更多信息)。如果你关心性能,尝试通过遍历arguments对象来构造一个新的数组。另一种方法是使用被忽视的Array构造函数作为一个函数:

+

警告:对参数使用slice会阻止某些JavaScript引擎中的优化 (比如 V8 - 更多信息)。如果你关心性能,尝试通过遍历arguments对象来构造一个新的数组。另一种方法是使用被忽视的Array构造函数作为一个函数:

var args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
 
@@ -93,20 +93,14 @@ var args = [...arguments];
arguments.callee
指向参数所属的当前执行的函数。
-
-
-
-

指向调用当前函数的函数。

-
arguments.length
传递给函数的参数数量。
arguments[@@iterator]
返回一个新的{{jsxref("Array/@@iterator", "Array 迭代器", "", 0)}} 对象,该对象包含参数中每个索引的值。
-
-
-

注意: 在严格模式下,arguments对象已与过往不同。arguments[@@iterator]不再与函数的实际形参之间共享,同时caller属性也被移除。

+
+

备注:在严格模式下,arguments对象已与过往不同。arguments[@@iterator]不再与函数的实际形参之间共享,同时caller属性也被移除。

例子

@@ -149,7 +143,7 @@ myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");

这个例子定义了一个函数通过一个字符串来创建HTML列表。这个函数唯一正式声明了的参数是一个字符。当该参数为 "u" 时,创建一个无序列表 (项目列表);当该参数为 "o" 时,则创建一个有序列表 (编号列表)。该函数定义如下:

-
function list(type) {
+
function list(type) {
   var result = "<" + type + "l><li>";
   var args = Array.prototype.slice.call(arguments, 1);
   result += args.join("</li><li>");
@@ -160,7 +154,7 @@ myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");

你可以传递任意数量的参数到该函数,并将每个参数作为一个项添加到指定类型的列表中。例如:

-
var listHTML = list("u", "One", "Two", "Three");
+
var listHTML = list("u", "One", "Two", "Three");
 
 /* listHTML is:
 
@@ -257,7 +251,7 @@ func(); // undefined
 
 

浏览器兼容

-

{{Compat("javascript.functions.arguments")}}

+{{Compat}}

相关链接

-- cgit v1.2.3-54-g00ecf