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/global_objects/function/apply/index.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/function/apply') diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html index 67a69174e6..bee3572f70 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html @@ -11,7 +11,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply

apply() 方法调用一个具有给定this值的函数,以及以一个数组(或类数组对象)的形式提供的参数。

-
注意:call()方法的作用和 apply() 方法类似,区别就是call()方法接受的是参数列表,而apply()方法接受的是一个参数数组
+
+

备注:call()方法的作用和 apply() 方法类似,区别就是call()方法接受的是参数列表,而apply()方法接受的是一个参数数组

+
{{EmbedInteractiveExample("pages/js/function-apply.html")}}
@@ -45,7 +47,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply

从 ECMAScript 第5版开始,可以使用任何种类的类数组对象,就是说只要有一个 length 属性和(0..length-1)范围的整数属性。例如现在可以使用 {{domxref("NodeList")}} 或一个自己定义的类似 {'length': 2, '0': 'eat', '1': 'bananas'} 形式的对象。

-

需要注意:Chrome 14 以及 Internet Explorer 9 仍然不接受类数组对象。如果传入类数组对象,它们会抛出异常。

+

备注: Chrome 14 以及 Internet Explorer 9 仍然不接受类数组对象。如果传入类数组对象,它们会抛出异常。

示例

@@ -118,7 +120,7 @@ var min = minOfArray([5, 6, 2, 3, 7]);
-

注意: 上面使用的Object.create()方法相对来说比较新。另一种可选的方法,请考虑如下替代方法:

+

备注: 上面使用的Object.create()方法相对来说比较新。另一种可选的方法,请考虑如下替代方法:

Using {{jsxref("Object/__proto__", "Object.__proto__")}}:

@@ -166,7 +168,9 @@ console.log(myInstance instanceof MyConstructor); // logs "true" console.log(myInstance.constructor);              // logs "MyConstructor" -
注意: 这个非native的Function.construct方法无法和一些native构造器(例如Date)一起使用。 在这种情况下你必须使用Function.bind方法(例如,想象有如下一个数组要用在Date构造器中: [2012, 11, 4];这时你需要这样写: new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))() – -无论如何这不是最好的实现方式并且也许不该用在任何生产环境中).
+
+

备注: 这个非native的Function.construct方法无法和一些native构造器(例如Date)一起使用。 在这种情况下你必须使用Function.bind方法(例如,想象有如下一个数组要用在Date构造器中: [2012, 11, 4];这时你需要这样写: new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))() – -无论如何这不是最好的实现方式并且也许不该用在任何生产环境中).

+

规范

-- cgit v1.2.3-54-g00ecf