Reflect.apply()
The Reflect.apply() method calls a target function
with a this value and an argument array.
Reflect.apply(function) is similar to
function.apply().
Example
function greet(message) {
return message + ", " + this.name;
}
const person = {name: "Jan"};
let msg = Reflect.apply(greet, person, ["Hello"]);
Try it Yourself »
Same as using greet.apply():
let msg = greet.apply(person, ["Hello"]);
Try it Yourself »
Reflect.apply(function) is preferred before function.apply() when:
- You are doing meta-programming
- You are inside a Proxy handler
- You want consistent behaviors (no silent errors)
- You want to mirror JavaScript's internal operations
Syntax
Reflect.apply(function, this, arguments)
Parameters
| Parameter | Description |
|---|---|
| function | Required. The target object (function). |
| this | Optional. The this value for the call. |
| arguments | Optional. An array-like object of function arguments. |
Return Value
| Type | Description |
|---|---|
| Value | The return value from the function. |
Errors
| Type | Description |
|---|---|
| TypeError | Thrown if function is not a function or arguments is not an object. |
Browser Support
Reflect.apply() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |