From 310fd066e91f454b990372ffa30e803cc8120975 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:56:40 +0100 Subject: unslug zh-cn: move --- .../global_objects/proxy/handler/apply/index.html | 117 --------------------- 1 file changed, 117 deletions(-) delete mode 100644 files/zh-cn/web/javascript/reference/global_objects/proxy/handler/apply/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/proxy/handler/apply') diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/apply/index.html b/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/apply/index.html deleted file mode 100644 index 62b8b67f5f..0000000000 --- a/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/apply/index.html +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: handler.apply() -slug: Web/JavaScript/Reference/Global_Objects/Proxy/handler/apply -tags: - - ECMAScript6 - - JavaScript - - Method - - Proxy -translation_of: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/apply ---- -
{{JSRef}}
- -

handler.apply() 方法用于拦截函数的调用。

- -
{{EmbedInteractiveExample("pages/js/proxyhandler-apply.html", "taller")}}
- - - -

语法

- -
var p = new Proxy(target, {
-  apply: function(target, thisArg, argumentsList) {
-  }
-});
-
- -

参数

- -

以下是传递给apply方法的参数,this上下文绑定在handler对象上.

- -
-
target
-
目标对象(函数)。
-
thisArg
-
被调用时的上下文对象。
-
argumentsList
-
被调用时的参数数组。
-
- -

返回值

- -

apply方法可以返回任何值。

- -

描述

- -

handler.apply 方法用于拦截函数的调用。

- -

拦截

- -

该方法会拦截目标对象的以下操作:

- - - -

约束

- -

如果违反了以下约束,代理将抛出一个TypeError:

- -

target必须是可被调用的。也就是说,它必须是一个函数对象。

- -

示例

- -

以下代码演示如何捕获函数的调用。

- -
var p = new Proxy(function() {}, {
-  apply: function(target, thisArg, argumentsList) {
-    console.log('called: ' + argumentsList.join(', '));
-    return argumentsList[0] + argumentsList[1] + argumentsList[2];
-  }
-});
-
-console.log(p(1, 2, 3)); // "called: 1, 2, 3"
-                         // 6
-
- -

规范

- - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES2015', '#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist', '[[Call]]')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist', '[[Call]]')}}{{Spec2('ESDraft')}} 
- -

浏览器兼容性

- -
- - -

{{Compat("javascript.builtins.Proxy.handler.apply")}}

-
- -

另见

- - -- cgit v1.2.3-54-g00ecf