Javascript - Reflect and Function.prototype

Introduction

It is recommended to use Reflect when calling methods on Function.prototype.

If the arguments list is null or undefined, Function.prototype.apply will call the function with no arguments, whereas Reflect.apply will throw an error.

Demo

function sayHello() { 
    console.log(`${this.name} says hello`); 
} 

const person = { // www. j a va  2s  .co m
    name: "Jack" 
}; 

Function.prototype.apply.call(sayHello, person); 
Reflect.apply(sayHello, person); 
Reflect.apply(sayHello, person, []);

Result

Related Topic