--- title: Reflect.apply() slug: Web/JavaScript/Reference/Global_Objects/Reflect/apply tags: - ECMAScript6 - JavaScript - Reflect - metodo translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/apply ---
O método estático Reflect
.apply()
chama uma função alvo com os argumentos especificados.
Reflect.apply(target, thisArgument, argumentsList)
this"
que será usado pela function do target.target
deve ser chamado.O resultado da função alvo chamada com o this
e argumentos especificados.
Um {{jsxref("TypeError")}}, se a função especificada no target não for invocável.
No ES5, tipicamente é usado o método {{jsxref("Function.prototype.apply()")}} para chamar uma função com o valor de this e argumentos
fornecidos como um array (ou um array-like object).
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
Com o Reflect.apply
isso se torna menos verboso e mais fácil de entender.
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"
Especificação | Status | Comentário |
---|---|---|
{{SpecName('ES6', '#sec-reflect.apply', 'Reflect.apply')}} | {{Spec2('ES6')}} | Definição inicial. |
{{SpecName('ESDraft', '#sec-reflect.apply', 'Reflect.apply')}} | {{Spec2('ESDraft')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 49 | {{CompatGeckoDesktop(42)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile(42)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |