mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
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>
4 lines
151 B
TypeScript
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);
|