An open API service indexing awesome lists of open source software.

https://github.com/caiogondim/invoke-without-new.js

Invoke constructors without new
https://github.com/caiogondim/invoke-without-new.js

Last synced: 3 months ago
JSON representation

Invoke constructors without new

Awesome Lists containing this project

README

        

# invoke-without-new

Add capability to invoke constructors without `new`.

## Install

```bash
npm install --save invoke-without-new
```

## Usage

### As a function

```js
// 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

```js
// 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](https://caiogondim.com)  · 
GitHub [@caiogondim](https://github.com/caiogondim)  · 
Twitter [@caio_gondim](https://twitter.com/caio_gondim)