C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.apply() MethodThe static Reflect.apply() method of JavaScript is used to call a function using the specified argument. Syntax
Reflect.apply(target, thisArgument, argumentsList) Parameter
target: It is the target function to call. thisArgument: It is the value of this provided for the call to target. ArgumentsList: It is an array-like object specifying the argument with which target should be called. Return
The result of calling the given target function with the specified this value and arguments. ExceptionsThis method will throw a TypeError if the target is not callable. Example 1
function g (a, b) {
this.x = a;
this.y = b;
}const obj = {};
Reflect.apply ( g , obj, [33,44] );
console.log( obj );
Output: Object { x: 33, y: 44 }
Example 2
var whatsThis = function() { console.log(this); }
Reflect.apply(whatsThis, 'hello', []);
// Call a function that takes a variable number of args
var numbers = [3, 20, 1, 55];
console.log(Reflect.apply(Math.max, undefined, numbers));
Output: "hello" 55 Example 3
console.log(Reflect.apply(Math.floor, undefined, [45]));
console.log(Reflect.apply(String.fromCharCode, undefined, [104, 101,103,105]));
console.log(Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index);
console.log(Reflect.apply(''.charAt, 'Rahul', [3]));
Output: 45
"hegi"
4
"u"
Next TopicJavaScript Reflect
|