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
- Host: GitHub
- URL: https://github.com/caiogondim/invoke-without-new.js
- Owner: caiogondim
- Created: 2018-04-07T18:37:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-18T16:46:28.000Z (over 5 years ago)
- Last Synced: 2025-03-11T12:40:55.645Z (3 months ago)
- Language: JavaScript
- Homepage: https://npm.im/invoke-without-new
- Size: 104 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)