Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Reflect.apply()

この記事は編集レビューを必要としています。ぜひご協力ください

これは Harmony(ECMAScript 6) 提案の一部であり、実験段階の技術です。
この技術の仕様は安定していません。ブラウザ互換性の一覧表を確認してください。またこれらの構文や動作は、仕様変更などにより、新しいバージョンのブラウザでは変更される可能性があるという点に注意してください。

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

構文

Reflect.apply(target, thisArgument, argumentsList)

パラメータ

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

スローされるError

targetが呼び出せない場合、TypeErrorがスローされます。

説明

ES5では、通常関数を呼び出すためにthis値と配列(または配列様のオブジェクト)として提供される引数 を渡してFunction.prototype.apply()メソッドを使用します。

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"

仕様

仕様 状態 コメント
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Reflect.apply' in that specification.
Standard Initial definition.

ブラウザ実装状況

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 未サポート 42 (42) 未サポート 未サポート 未サポート
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未サポート 未サポート 42.0 (42) 未サポート 未サポート 未サポート

関連項目

ドキュメントのタグと貢献者

 このページの貢献者: YuichiNukiyama
 最終更新者: YuichiNukiyama,