Socket
Socket
Sign inDemoInstall

as-factory

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    as-factory

Create factories from classes


Version published
Maintainers
1
Install size
29.6 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 02 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc