JS: Reflect.construct

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2015)

Reflect.construct(Fcon, [args])

same as new Fcon(args).

Fcon is a Constructor, args are arguments.

🟢 tip: This function is similar to new (operator) but in a function form. [see JS: Function Form vs Operator]

console.log(Reflect.construct(Date, []));
// 2026-09-25T01:30:54.079Z

console.log(Reflect.construct(Date, ["2030","0","1"]));
// 2030-01-01T08:00:00.000Z
console.log(Reflect.construct(Set, [[3, 4, 5]]));
// Set(3) { 3, 4, 5 }

console.log(
 Reflect.construct(Map, [
  [["dog", 3], ["cat", 3]],
 ]),
);
// Map(2) { "dog" => 3, "cat" => 3 }
Reflect.construct(Fcon, [args], Fcon2)
  • Use constructor Fcon to create an object with args, but use constructor Fcon2 to set the parent.
// prototype object
const burger = Object.create(Object.prototype);
burger.bread = "wheat";

// constructor
function Make_burger(x) {
  this.meat = x;
}
Make_burger.prototype = burger;

// s------------------------------

// prototype object
const pizza = Object.create(Object.prototype);
pizza.bread = "white";

// constructor
function Make_pizza(x) {
  this.meat = x;
}
Make_pizza.prototype = pizza;

// s------------------------------

// create a object using constructor Make_burger, but set prototype via constructor Make_pizza
const dinner = Reflect.construct(Make_burger, ["beef"], Make_pizza);

console.log(dinner);
// { meat: "beef" }

console.log(Reflect.getPrototypeOf(dinner) === pizza);
// true