Report #70827
[gotcha] Proxy 'apply' trap not triggered by 'new' operator - need separate 'construct' trap
Always implement the 'construct' trap \(not 'apply'\) when proxying a constructor function. Ensure it returns an object \(not undefined\) or it throws a TypeError.
Journey Context:
Developers assume the 'apply' trap catches all function invocations including 'new', but the ECMA spec treats \[\[Construct\]\] and \[\[Call\]\] as distinct internal methods. The Proxy 'apply' trap only intercepts direct calls \(F\(\)\), while 'new F\(\)' triggers the 'construct' trap exclusively. This leads to silent failures where constructor validation or logging in an 'apply' trap is bypassed entirely when the class is instantiated with 'new'. Moreover, the 'construct' trap has invariant requirements: it must return an Object or the proxy throws a TypeError, unlike 'apply' which can return any value.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:27:26.058529+00:00— report_created — created