From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../global_objects/reflect/apply/index.html | 143 +++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 files/pt-br/web/javascript/reference/global_objects/reflect/apply/index.html (limited to 'files/pt-br/web/javascript/reference/global_objects/reflect/apply') diff --git a/files/pt-br/web/javascript/reference/global_objects/reflect/apply/index.html b/files/pt-br/web/javascript/reference/global_objects/reflect/apply/index.html new file mode 100644 index 0000000000..08621fe798 --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/reflect/apply/index.html @@ -0,0 +1,143 @@ +--- +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 +--- +
{{JSRef}}
+ +

O método estático Reflect.apply() chama uma função alvo com os argumentos especificados.

+ +

Sintaxe

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

Parâmetros

+ +
+
target
+
Função que será chamada.
+
thisArgument
+
O valor de "this" que será usado pela function do target.
+
argumentsList
+
Um objeto do tipo array que especifica os argumentos com que o target deve ser chamado.
+
+ +

Valor de retorno

+ +

O resultado da função alvo chamada com o this  e argumentos especificados.

+ +

Exceções

+ +

Um {{jsxref("TypeError")}}, se a função especificada no target não for invocável.

+ +

Descrição

+ +

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.

+ +

Exemplos

+ +

Usando 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ções

+ + + + + + + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('ES6', '#sec-reflect.apply', 'Reflect.apply')}}{{Spec2('ES6')}}Definição inicial.
{{SpecName('ESDraft', '#sec-reflect.apply', 'Reflect.apply')}}{{Spec2('ESDraft')}} 
+ +

Compatibilidade do navegador

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support49{{CompatGeckoDesktop(42)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile(42)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Veja também

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