This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Reflect.apply()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2016๋…„ 9์›”โฉ.

Reflect.apply() ์ •์  ๋ฉ”์„œ๋“œ๋Š” ๋Œ€์ƒ ํ•จ์ˆ˜๋ฅผ ์ฃผ์–ด์ง„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

console.log(Reflect.apply(Math.floor, undefined, [1.75]));
// Expected output: 1

console.log(
  Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]),
);
// Expected output: "hello"

console.log(
  Reflect.apply(RegExp.prototype.exec, /ab/, ["confabulation"]).index,
);
// Expected output: 4

console.log(Reflect.apply("".charAt, "ponies", [3]));
// Expected output: "i"

๊ตฌ๋ฌธ

js
Reflect.apply(target, thisArgument, argumentsList);

๋งค๊ฐœ๋ณ€์ˆ˜

target

ํ˜ธ์ถœํ•  ๋Œ€์ƒ ํ•จ์ˆ˜.

thisArgument

ํ˜ธ์ถœ์—์„œ target์˜ this๋กœ ์‚ฌ์šฉํ•  ๊ฐ’.

argumentsList

target์„ ํ˜ธ์ถœํ•  ๋•Œ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌํ•  ๋ฐฐ์—ดํ˜• ๊ฐ์ฒด.

๋ฐ˜ํ™˜ ๊ฐ’

์ฃผ์–ด์ง„ this ๊ฐ’๊ณผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋Œ€์ƒ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ ๊ฒฐ๊ณผ.

์˜ˆ์™ธ

target์ด ํ˜ธ์ถœ ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๊ฐ€ ์•„๋‹ˆ๋ฉด TypeError.

์„ค๋ช…

ES5์—์„œ๋Š” Function.prototype.apply() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด, ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ this ๊ฐ’์„ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐฐ์—ด(๋˜๋Š” ๋ฐฐ์—ดํ˜• ๊ฐ์ฒด)์—์„œ ๋„˜๊ฒจ์ค„ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

js
Function.prototype.apply.call(Math.floor, undefined, [1.75]);

Reflect.apply() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ™์€ ์ž‘์—…์„ ๋” ์‰ฝ๊ณ  ์œ ๋ คํ•˜๊ฒŒ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ

Reflect.apply() ์‚ฌ์šฉํ•˜๊ธฐ

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"

๋ช…์„ธ

Specification
ECMAScriptยฎ 2026 Language Specification
# sec-reflect.apply

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ