0.0.1 • Published 9 years ago

as-factory v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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();
0.0.1

9 years ago