JavaScript Proxy handler.construct() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Proxy trap

Definition

handler.construct(target, argumentsList, newTarget) is a trap that runs when you use the new keyword on a Proxy. It only works when the target of the Proxy is a constructor, such as a class or a normal function.

Inside the trap you can log the creation, change the arguments, or even return a different object. To create the object in the normal way, use Reflect.construct(target, argumentsList, newTarget). The trap must return an object.

Remember
const handler = {
  construct(target, argumentsList, newTarget) { ... }
};

target         → the original class or constructor
argumentsList  → an array with the arguments
newTarget      → the constructor that new was used on

return value   → must be an object, or TypeError

Syntax

Wrap a class in a Proxy and add a construct trap to the handler.

JavaScript
class User {
  constructor(name) {
    this.name = name;
  }
}

const TrackedUser = new Proxy(User, {
  construct(target, args, newTarget) {
    console.log("Creating " + args[0]);
    return Reflect.construct(target, args, newTarget);
  }
});

const ann = new TrackedUser("Ann");   // Creating Ann
CallWhat it does
new proxy(1, 2)Using new on the Proxy runs the trap.
Reflect.construct(proxy, [1, 2])The function-style version. It runs the trap too.
class Child extends proxy {}Extending a Proxy runs the trap when a Child is created.
proxy(1, 2)A call without new does not run construct. It would use the apply trap.

A standard JavaScript Proxy trap (ES2015). You write it inside the handler object that you pass to new Proxy(). JavaScript calls it for you. No import required. Siblings: Proxy.revocable(), handler.apply(), handler.defineProperty(), handler.deleteProperty(), handler.get(), handler.getOwnPropertyDescriptor(), handler.getPrototypeOf(), handler.has(), handler.isExtensible(), handler.ownKeys(), handler.preventExtensions(), handler.set(), handler.setPrototypeOf().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
handler.construct(target, argumentsList, newTarget)

// target        : the original constructor
// argumentsList : an array of the arguments
// newTarget     : the constructor that new was called on
// returns       : an object
// throws        : TypeError if the result is not an object

Parameters

ParameterDescription
targetThe original class or constructor function that the Proxy wraps.
argumentsListA real array with the arguments that were passed to new. It is empty when there are none.
newTargetThe constructor that new was used on. It is the Proxy itself, unless a subclass is being created. Pass it on to Reflect.construct().

Return Value

Return ValueDescription
ObjectThe new object. It becomes the result of new proxy(...). Usually this is the result of Reflect.construct().
TypeError (thrown)The trap returned something that is not an object, such as a number or undefined.

JavaScript Examples

Example 1 — Log Every Object Creation

Wrap a class so that every new writes a note, and then creates the object in the normal way with Reflect.construct().

JavaScript
class User {
  constructor(name) {
    this.name = name;
  }
}

const logs = [];
const TrackedUser = new Proxy(User, {
  construct(target, args, newTarget) {
    logs.push("new User(" + args.join(", ") + ")");
    return Reflect.construct(target, args, newTarget);
  }
});

const ann = new TrackedUser("Ann");
const bob = new TrackedUser("Bob");

console.log(ann.name + " and " + bob.name);
console.log("Log: " + logs.join(" | "));
console.log("instanceof User: " + (ann instanceof User));
console.log("instanceof TrackedUser: " + (ann instanceof TrackedUser));
Try It Yourself

How It Works

  1. A class proxy. new TrackedUser("Ann") does not run the class directly. It runs the construct trap with args as ["Ann"].
  2. Log, then create. The trap saves a note and returns Reflect.construct(target, args, newTarget), which builds a normal User object.
  3. instanceof works. Passing newTarget along keeps the prototype correct, so the objects count as both User and TrackedUser.

Example 2 — Fix the Arguments Before Creating

The trap can check the arguments first. Here, a number that is missing or is not a number becomes 0.

JavaScript
class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

const SafePoint = new Proxy(Point, {
  construct(target, args, newTarget) {
    const x = typeof args[0] === "number" ? args[0] : 0;
    const y = typeof args[1] === "number" ? args[1] : 0;
    return Reflect.construct(target, [x, y], newTarget);
  }
});

console.log(JSON.stringify(new SafePoint(3, 4)));
console.log(JSON.stringify(new SafePoint(5)));
console.log(JSON.stringify(new SafePoint("a", null)));
console.log(JSON.stringify(new Point(5)));
Try It Yourself

How It Works

  1. Check each argument. typeof args[0] === "number" keeps real numbers and replaces everything else with 0.
  2. Create with the fixed list. Reflect.construct(target, [x, y], newTarget) builds the object from the cleaned arguments, so a missing y becomes 0.
  3. Plain class compared. new Point(5) has no trap, so y is undefined and JSON.stringify() leaves it out.

Example 3 — One Shared Object and Common Errors

The trap can return an object that already exists, which makes a singleton. Then see two mistakes that throw a TypeError. The catch blocks print the error type only.

JavaScript
class Settings {
  constructor() {
    this.theme = "light";
  }
}

let instance = null;
const Single = new Proxy(Settings, {
  construct(target, args, newTarget) {
    if (instance === null) {
      instance = Reflect.construct(target, args, newTarget);
    }
    return instance;
  }
});

const a = new Single();
const b = new Single();
a.theme = "dark";
console.log("Same object: " + (a === b));
console.log("b.theme: " + b.theme);

const Bad = new Proxy(function () {}, {
  construct() {
    return 42;
  }
});
try {
  new Bad();
} catch (err) {
  console.log("Returns a number: " + err.name);
}

const Arrow = new Proxy(() => 1, {
  construct() {
    return {};
  }
});
try {
  new Arrow();
} catch (err) {
  console.log("Arrow function target: " + err.name);
}
Try It Yourself

How It Works

  1. Create once. The first new Single() builds a Settings object and saves it. Every later new returns that same object.
  2. Shared on purpose. a and b are the same object, so changing the theme through a shows through b.
  3. Two mistakes. A trap that returns 42 breaks the rule that it must return an object. An arrow function cannot be used with new, so the Proxy cannot either.

Browser & Runtime Support

handler.construct() is part of ES2015 (ES6), together with the Proxy object and the Reflect object. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

handler.construct()

Supported in Chrome 49+, Edge 12+, Firefox 49+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 49+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 49+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 36+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 49+ · Chromium based
Supported
Node.js 6+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
handler.construct() Excellent

Bottom line: Safe to use in every current browser and in Node.js. A Proxy cannot be faked in old browsers, so do not use it where Internet Explorer must work.

Frequently Asked Questions

It is a method of the handler object that runs when you use new on a Proxy. It receives the original constructor, an array of arguments and newTarget, and it must return an object.
Use Reflect.construct(target, args, newTarget). It builds the object the normal way, including class fields and inheritance, and you can return the result from the trap.
Either the target is not a constructor (for example an arrow function), or your trap returned something that is not an object. Always return an object from construct.
No. A call without new uses the apply trap instead. For a class, calling it without new throws a TypeError anyway.
It is the constructor that new was used on. For new proxy() it is the Proxy itself. For a subclass, it is the subclass. Pass it to Reflect.construct() so the new object gets the right prototype.

Next: handler.defineProperty()

Learn how a Proxy can watch and block the creation of properties with the defineProperty trap.

handler.defineProperty() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful