--- 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 ---
静的な Reflect.apply() メソッドは、指定された引数とともに対象となる関数を呼び出します。
Reflect.apply(target, thisArgument, argumentsList)
targetthisArgumenttarget の呼び出す際の this 値を提供する。argumentsListtarget と一緒に呼び出す引数を指定する配列風オブジェクト。指定された target 値と引数の条件で対象の関数を呼び出したときの結果です。
{{jsxref("TypeError")}}: target が呼び出せない場合。
ES5 では、ふつう {{jsxref("Function.prototype.apply()")}} メソッドを使用することで、指定された this の値と arguments で配列 (または 配列風オブジェクト) により引数を指定することで、関数を呼び出すことができます。
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
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")}}