Files
scriptc/tests/diagnostics/new-target-plain-function.ts
T
Malte UblandClaude Opus 5.5 ac940ed936 Support new.target in class constructors
Inside a class constructor new.target is the class of the instance under
construction. A compiled new allocates the instance with its concrete class
before the constructor chain runs, and the class hierarchy is closed, so
new.target lowers to a static dispatch over the constructor's class and its
descendants (deepest instanceof first). new.target.name reads the exact
class's name and new.target === C is an exact-class test, without a class
value, so subclasses may construct with other signatures. new.target as a
class value requires every subclass to share the constructor's signature.
Plain functions and function-local subclasses keep explicit refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 17:43:09 -07:00

4 lines
151 B
TypeScript

// new.target in a plain function has no invocation record to read.
function F(this: unknown) { console.log(new.target === undefined); }
F.call(null);