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
|
---
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
---
<div>{{JSRef}}</div>
<p><code><strong>Reflect</strong></code><strong><code>.apply()</code></strong> 정적 메서드는 대상 함수를 주어진 매개변수로 호출합니다.</p>
<div>{{EmbedInteractiveExample("pages/js/reflect-apply.html")}}</div>
<h2 id="구문">구문</h2>
<pre class="syntaxbox">Reflect.apply(<em>target</em>, <em>thisArgument</em>, <em>argumentsList</em>)
</pre>
<h3 id="매개변수">매개변수</h3>
<dl>
<dt><code>target</code></dt>
<dd>호출할 대상 함수.</dd>
<dt><code>thisArgument</code></dt>
<dd>호출에서 <code>target</code>의 <code>this</code>로 사용할 값.</dd>
<dt><code>argumentsList</code></dt>
<dd><code>target</code>을 호출할 때 매개변수로 전달할 배열형 객체.</dd>
</dl>
<h3 id="반환_값">반환 값</h3>
<p>주어진 <code>this</code> 값과 매개변수로 대상 함수를 호출한 결과.</p>
<h3 id="예외">예외</h3>
<p><code>target</code>이 호출 가능한 객체가 아니면 {{jsxref("TypeError")}}.</p>
<h2 id="설명">설명</h2>
<p>ES5에서는 {{jsxref("Function.prototype.apply()")}} 메서드를 사용해, 함수를 호출할 때 <code>this</code> 값을 지정하거나 매개변수를 배열(또는 배열형 객체)에서 넘겨줄 수 있었습니다.</p>
<pre class="brush: js">Function.prototype.apply.call(Math.floor, undefined, [1.75]);</pre>
<p><code>Reflect.apply()</code> 메서드를 사용해 같은 작업을 더 쉽고 유려하게 수행할 수 있습니다.</p>
<h2 id="예제">예제</h2>
<h3 id="Reflect.apply_사용하기"><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="명세">명세</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-reflect.apply', 'Reflect.apply')}}</td>
</tr>
</tbody>
</table>
<h2 id="브라우저_호환성">브라우저 호환성</h2>
<p>{{Compat("javascript.builtins.Reflect.apply")}}</p>
<h2 id="같이_보기">같이 보기</h2>
<ul>
<li>{{jsxref("Reflect")}}</li>
<li>{{jsxref("Function.prototype.apply()")}}</li>
</ul>
|