mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
* Expand static three.js workflows and host integration * Preserve JavaScript class state in static three.js workflows * Preserve inferred JavaScript behavior across static workflows * Preserve inferred callables and native compatibility boundaries * Retain annotated JavaScript factory exports and bootstrap-safe call spreads * Preserve Buffer and child callback identities in static packages * Clarify JavaScript symbol spread support
29 lines
972 B
JavaScript
29 lines
972 B
JavaScript
class Base {
|
|
constructor(value) { this.value = value; }
|
|
read() { return this.value; }
|
|
}
|
|
class Child extends Base {
|
|
read() { return this.value + 10; }
|
|
}
|
|
function extract(value) { return value.read; }
|
|
const base = new Base(1);
|
|
const first = extract(base);
|
|
const child = new Child(2);
|
|
const second = extract(child);
|
|
console.log(first.call(child), second.call(base), second === child.read);
|
|
const dynamic = JSON.parse('{}');
|
|
dynamic.base = base;
|
|
dynamic.child = child;
|
|
const methodName = JSON.parse('"read"');
|
|
console.log(dynamic.base[methodName].call(child), dynamic.child[methodName].call(base));
|
|
class Holder {
|
|
constructor() { this.child = null; }
|
|
attach(value) { this.child = value; }
|
|
extract() { return this.child.read; }
|
|
}
|
|
const holder = new Holder();
|
|
holder.attach(child);
|
|
console.log(Boolean(holder.child && holder.child.read), holder.extract().call(base));
|
|
child.read = function () { return this.value + 100; };
|
|
console.log(holder.extract().call(child));
|