Files
scriptc/tests/corpus/class-instance-constructor.js
Chris Tate df78e89342 Compile three.js scenes, cameras, and geometry
- Compile scene hierarchies, synchronized rotations, and perspective camera transforms.
- Support box and buffer geometry, bounds, normals, and index selection.
- Preserve JavaScript constructor and callback behavior in native LLVM and WASM builds.
2026-09-29 22:49:55 -05:00

25 lines
979 B
JavaScript

class Value {
constructor(x = 1) { this.x = x; }
clone() { return new this.constructor(this.x); }
reset() { return new this.constructor(); }
}
class Child extends Value {
constructor(x = 2, extra = 3) { super(x); this.extra = extra; }
}
class Leaf extends Child {}
const a = new Value(4), b = new Child(5), c = new Leaf(6);
for (const source of [a, b, c]) {
const copy = source.clone();
console.log(copy !== source, copy.x, copy instanceof Value, copy instanceof Child, copy instanceof Leaf);
console.log(source.reset().x);
}
let order = '';
function receiver() { order += 'r'; return b; }
function argument() { order += 'a'; return 7; }
const selected = new (receiver().constructor)(argument());
console.log(order, selected.x, selected instanceof Child);
class Other { constructor(x = 9) { this.x = x; } }
/** @returns {Value | Other} */
function choose(flag) { return new (flag ? Value : Other)(argument()); }
console.log(choose(true).x, choose(false).x, order);