1.1.1 • Published 4 years ago

invoke-without-new v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

invoke-without-new

Add capability to invoke constructors without new.

Install

npm install --save invoke-without-new

Usage

As a function

// foo.js
const invokeWithoutNew = require('invoke-without-new')

class Foo {
  constructor() {
    this.bar = 1
  }
}

module.exports = invokeWithoutNew(Foo)

// index.js
const Foo = require('foo')
const foo1 = Foo() // works
const foo2 = new Foo() // works

As a decorator

// foo.js
const invokeWithoutNew = require('invoke-without-new')

@invokeWithoutNew
class Foo {
  constructor() {
    this.bar = 1
  }
}

module.exports = Foo

// index.js
const Foo = require('foo')
const foo1 = Foo() // works
const foo2 = new Foo() // works

caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim