mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
- Preserve fresh constructor identity and shared captures across local class instances. - Carry constructors through unknown values without a JavaScript engine. - Support runtime-length spreads into fixed and rest parameters.
19 lines
592 B
TypeScript
19 lines
592 B
TypeScript
function makeCounter(start: number) {
|
|
let value = start;
|
|
const Local = class Counter {
|
|
read(): number { return value; }
|
|
increment(): number { return ++value; }
|
|
callback = (): number => value;
|
|
};
|
|
value++;
|
|
return Local;
|
|
}
|
|
const First = makeCounter(10);
|
|
const Second = makeCounter(20);
|
|
const a = new First();
|
|
const b = new First();
|
|
const c = new Second();
|
|
console.log(First.name, First === First, First === Second);
|
|
console.log(a.read(), b.increment(), a.callback(), c.read());
|
|
console.log(a instanceof First, a instanceof Second, c instanceof First, c instanceof Second);
|