Reflect.construct()
The Reflect.construct() method acts like the
new operator.
The Reflect.construct() method creates an instance of a new object.
Example
// Create a new Array
const colors = Reflect.construct(Array, ["red", "green", "blue"]);
Try it Yourself »
Same as the new keyword:
// Create a new Array
const colors = new Array(["red", "green", "blue"]));
Try it Yourself »
Syntax
Reflect.construct(obj, args [, newTarget])
Parameters
| Parameter | Description |
|---|---|
| obj | Required. The target object. |
| args | Optional. An array-like object of arguments to be passed. |
| newTarget | Optional. Anoter target parameter for subclassing custom objects. |
Return Value
| Type | Description |
|---|---|
| Object | The new object constructed. |
Errors
| Type | Description |
|---|---|
| TypeError | Thrown if obj or newTarget is not a constructor, or if args is not an object. |
Reflect Methods:
Reflect.apply()
Reflect.construct()
Reflect.defineProperty()
Reflect.deleteProperty()
Reflect.get()
Reflect.getOwnPropertyDescriptor()
Reflect.getPrototypeOf()
Reflect.has()
Reflect.isExtensible()
Reflect.ownKeys()
Reflect.preventExtensions()
Reflect.set()
Reflect.setPrototypeOf()
Browser Support
Reflect.construct() 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 |