From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/reflect/apply/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/reflect/apply/index.html (limited to 'files/ja/web/javascript/reference/global_objects/reflect/apply/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/reflect/apply/index.html b/files/ja/web/javascript/reference/global_objects/reflect/apply/index.html new file mode 100644 index 0000000000..d845544c01 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/reflect/apply/index.html @@ -0,0 +1,95 @@ +--- +title: Reflect.apply() +slug: Web/JavaScript/Reference/Global_Objects/Reflect/apply +tags: + - ECMAScript 2015 + - JavaScript + - Method + - Reference + - Reflect +translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/apply +--- +
{{JSRef}}
+ +

静的な Reflect.apply() メソッドは、指定された引数とともに対象となる関数を呼び出します。

+ +
{{EmbedInteractiveExample("pages/js/reflect-apply.html")}}
+ + + +

構文

+ +
Reflect.apply(target, thisArgument, argumentsList)
+
+ +

引数

+ +
+
target
+
呼び出し対象の関数。
+
thisArgument
+
target の呼び出す際の this 値を提供する。
+
argumentsList
+
target と一緒に呼び出す引数を指定する配列風オブジェクト。
+
+ +

返値

+ +

指定された target 値と引数の条件で対象の関数を呼び出したときの結果です。

+ +

例外

+ +

{{jsxref("TypeError")}}: target が呼び出せない場合。

+ +

解説

+ +

ES5 では、ふつう {{jsxref("Function.prototype.apply()")}} メソッドを使用することで、指定された this の値と arguments で配列 (または 配列風オブジェクト) により引数を指定することで、関数を呼び出すことができます。

+ +
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
+ +

Reflect.apply() を使うと、それほど冗長ではなく理解しやすくなります。

+ +

+ +

Reflect.apply() の使用

+ +
Reflect.apply(Math.floor, undefined, [1.75]);
+// 1;
+
+Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111])
+// "hello"
+
+Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index
+// 4
+
+Reflect.apply(''.charAt, 'ponies', [3])
+// "i"
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-reflect.apply', 'Reflect.apply')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Reflect.apply")}}

+ +

関連情報

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