JS Built-ins
Reflectconstructbeginner

Reflect.construct() - Date instanceof

πŸ“– Usage Example
function Point(x, y) { this.x = x; this.y = y }
const p = Reflect.construct(Point, [1, 2])
console.log(p.x, p.y)        // β†’ 1 2
console.log(p instanceof Point) // β†’ true

Reflect.construct() acts like the new operator but as a function, creating a new instance of the target constructor.

Reflect.construct(Date, [0]) creates a proper Date instance.

πŸ’‘ Hints (1)
  • β€’ Reflect.construct(Date, [ms]) is equivalent to new Date(ms).