as-factory
v0.0.1
Published
Create factories from classes
Downloads
3
Readme
Create a factory from a constructor/class definition.
Installation
npm install as-factory
Usage
import asFactory from 'as-factory';
@asFactory
export default class Greeter {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello ${this.name}`);
}
static sayNothing() {
console.log('...');
}
}
Elsewhere:
const greeter = new Greeter(); // Errors! Don't use "new"
Greeter.sayNothing(); // statics are copied
const greeter = Greeter('World'); // All good.
greeter.greet();