1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
---
title: Reflect.apply()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/apply
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/apply
---
<div>{{JSRef}}</div>
<div>Die statische Methode <code><strong>Reflect</strong></code><strong><code>.apply()</code></strong> ruft eine Zielfunktion mit den spezifizierten Parametern auf.</div>
<div> </div>
<div>{{EmbedInteractiveExample("pages/js/reflect-apply.html")}}</div>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">Reflect.apply(target, thisParameter, listeDerArgumente)
</pre>
<h3 id="Parameter">Parameter</h3>
<dl>
<dt>target</dt>
<dd>Die Funktion, die aufgerufen werden soll.</dd>
<dt>thisParameter</dt>
<dd>Der Wert von <code>this</code> der für den Aufruf bereitgestellt wird.</dd>
<dt>listeDerArgumente</dt>
<dd>Ein Array ähnliches Objekt welches die Parameter spezifiziert, mit denen die Zielfunktion aufgerufen wird.</dd>
</dl>
<h3 id="Rückgabewert">Rückgabewert</h3>
<p>Das Resultat des Aufruft, der Zielfunktion mit dem mitgegebenen <code>this</code> und den mitgegebenen Parametern.</p>
<h3 id="Ausnahmen">Ausnahmen</h3>
<p>Es wird ein {{jsxref("TypeError")}} geworfen, wenn die Zielfunktion nicht aufrufbar ist.</p>
<h2 id="Beschreibung">Beschreibung</h2>
<p>In ES5, ruft man typischerweise {{jsxref("Function.prototype.apply()")}} auf, um eine Funktion aufzurufen, der man einen bestimmten <code>this</code> mitgeben und die Parameter als Array (oder einem <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#Working_with_array-like_objects">array-like object</a>) definieren möchte.</p>
<pre class="brush: js">Function.prototype.apply.call(Math.floor, undefined, [1.75]);</pre>
<p>Durch <code>Reflect.apply</code> wird dieses Vorhaben kürzer und ist leichter zu verstehen.</p>
<h2 id="Beispiele">Beispiele</h2>
<h3 id="Verwendung_von_Reflect.apply()">Verwendung von <code>Reflect.apply()</code></h3>
<pre class="brush: js">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"
</pre>
<h2 id="Spezifikationen">Spezifikationen</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Spezifikation</th>
<th scope="col">Status</th>
<th scope="col">Kommentar</th>
</tr>
<tr>
<td>{{SpecName('ES2015', '#sec-reflect.apply', 'Reflect.apply')}}</td>
<td>{{Spec2('ES2015')}}</td>
<td>Ursprüngliche Definition.</td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-reflect.apply', 'Reflect.apply')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_kompabilität">Browser kompabilität</h2>
<p>{{Compat("javascript.builtins.Reflect.apply")}}</p>
<h2 id="Siehe_auch">Siehe auch</h2>
<ul>
<li>{{jsxref("Reflect")}}</li>
<li>{{jsxref("Function.prototype.apply()")}}</li>
</ul>
|