A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply below:

Reflect.apply() - JavaScript | MDN

Reflect.apply()

Baseline Widely available

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"
명세 브라우저 호환성 같이 보기

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4