The Reflect.construct(constructor, args, prototype) method

The Reflect.construct() method is used to invoke a function as a constructor. It's similar to the new operator. The function that will be invoked is called as the target constructor.

One special reason why you may want to use the Reflect.construct() method instead of the new operator is that you can target the constructor's prototype to match the prototype of another constructor.

The Reflect.construct() method takes three arguments:

  • The first argument is the target constructor.
  • The second argument is an array, specifying the arguments of the target constructor. This argument is optional.
  • The third argument is another constructor whose prototype will be used as the prototype of the ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.