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"
구문
Reflect.apply(target, thisArgument, argumentsList);
매ê°ë³ì
target-
í¸ì¶í ëì í¨ì.
thisArgument-
í¸ì¶ìì
targetìthisë¡ ì¬ì©í ê°. argumentsList-
targetì í¸ì¶í ë 매ê°ë³ìë¡ ì ë¬í ë°°ì´í ê°ì²´.
ë°í ê°
주ì´ì§ this ê°ê³¼ 매ê°ë³ìë¡ ëì í¨ì를 í¸ì¶í ê²°ê³¼.
ìì¸
targetì´ í¸ì¶ ê°ë¥í ê°ì²´ê° ìëë©´ TypeError.
ì¤ëª
ES5ììë Function.prototype.apply() ë©ìë를 ì¬ì©í´, í¨ì를 í¸ì¶í ë this ê°ì ì§ì íê±°ë 매ê°ë³ì를 ë°°ì´(ëë ë°°ì´í ê°ì²´)ìì ëê²¨ì¤ ì ìììµëë¤.
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
Reflect.apply() ë©ìë를 ì¬ì©í´ ê°ì ìì
ì ë ì½ê³ ì ë ¤íê² ìíí ì ììµëë¤.
ìì
>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"
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-reflect.apply> |