Files
scriptc/tests/fixtures/npm-static/node_modules/class-factory/classes.js
T
Chris Tate a5675b2279 Call factory-defined static methods with their receiver class
A static method that a function-local JavaScript class defines at
runtime and a program class inherits (Animal.extend("Dog")) is now
called directly with this bound to the receiver class when it captures
nothing from the factory's scope, so the subclass it builds has a static
base and constructs like Node.

Fixes #938
Co-authored-by: phall <25888173+phall1@users.noreply.github.com>
2026-10-17 17:31:30 -05:00

26 lines
566 B
JavaScript

// A class factory whose classes extend themselves through a static
// method: `extend` builds a subclass of whichever class it is called on.
function factory(base, name) {
const out = class extends base {
constructor(value) {
super(value);
this.kind = name;
}
static extend(name2) {
return factory(this, name2);
}
describe() {
return `${this.kind}:${this.value}`;
}
};
return out;
}
class Root {
constructor(value) {
this.value = value;
}
}
export function Class(name) {
return factory(Root, name);
}