JavaScript Reflect.construct() Method

The static Reflect.construct() method allows to invoke a constructor with a variable number of arguments. It gives also the added option to specify a different prototype.

Syntax

Parameter

target: It is the target function to call.

argumentsList: It is an array-like object specifying the arguments with which target should be called.

newTarget: It is a constructor whose prototype should be used. See also the new.target operator. If newTarget is not present, it will treat as a target.

Return

This method returns a new instance of the target (or newTarget if present), initialized by the target as a constructor with the given arguments.

Exceptions

This exception will throw a TypeError if target or newTarget are not constructors.

Example 1

Output:

 [1, 2, 3]
 [1, 2, 3]

Example 2

Output:

 6

Example 3

Output:

8
 6





Latest Courses