mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-19 05:29:46 +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.
17 lines
541 B
JavaScript
17 lines
541 B
JavaScript
function make(value) {
|
|
return class Stored {
|
|
read() { return value; }
|
|
matches(other) { return other === value; }
|
|
};
|
|
}
|
|
const Numbers = make(12);
|
|
const OtherNumbers = make(25);
|
|
const Strings = make("hello");
|
|
const a = new Numbers();
|
|
const b = new OtherNumbers();
|
|
const c = new Strings();
|
|
console.log(Numbers.name, Numbers === OtherNumbers);
|
|
console.log(a.read(), b.read(), c.read());
|
|
console.log(a.matches(12), b.matches(12), c.matches("hello"));
|
|
console.log(a instanceof Numbers, a instanceof OtherNumbers, c instanceof Strings);
|