# babel-plugin-transform-class-constructor-call

> This plugin allows Babel to transform class constructors (deprecated)

Latest version **6.24.1** (published 2017-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-class-constructor-call
pnpm add babel-plugin-transform-class-constructor-call
yarn add babel-plugin-transform-class-constructor-call
bun add babel-plugin-transform-class-constructor-call
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.24.1 |
| Published | 2017-04-07 |
| First published | 2015-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43993 |
| Maintainers | amasad, hzoo, jmm, loganfsmyth, sebmck, thejameskyle |
| Keywords | babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-class-constructor-call
- Repository: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-constructor-call
- npm.io page: https://npm.io/package/babel-plugin-transform-class-constructor-call

## Dependencies (3)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.22.0
- [babel-template](https://npm.io/package/babel-template.md) ^6.24.1
- [babel-plugin-syntax-class-constructor-call](https://npm.io/package/babel-plugin-syntax-class-constructor-call.md) ^6.18.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 6.24.1 (latest) — 2017-04-07
- 6.22.0 — 2017-01-20
- 6.18.0 — 2016-10-24
- 6.8.0 — 2016-05-02
- 6.6.5 — 2016-03-04
- 6.6.4 — 2016-03-02
- 6.5.0-1 — 2016-02-07
- 6.5.0 — 2016-02-07
- 6.4.0 — 2016-01-06
- 6.3.13 — 2015-12-04
- 6.2.4 — 2015-11-25
- 6.1.18 — 2015-11-12
- 6.1.17 — 2015-11-12
- 6.1.13 — 2015-11-12
- 6.1.10 — 2015-11-12
- … 6 more at https://npm.io/package/babel-plugin-transform-class-constructor-call/versions

## README

# babel-plugin-transform-class-constructor-call (deprecated)

> Proposal Withdrawn: can be solved with decorators.

This plugin allows Babel to transform class constructors.

It basically allows to use the [new.target](http://mdn.io/new.target) feature on ES2015 classes:

```js
class Point {

  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  call constructor(x, y) {
    return new Point(x, y);
  }

}

let p1 = new Point(1, 2); // OK
let p2 = Point(3, 4); // OK
```

## Example

### Date example
The javascript [Date](http://mdn.io/date) works this way:

```js
// You can get a Date instance using the new keyword
let now = new Date();
console.log(now.getMonth()); // Prints '3'
console.log(now.toString()); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)'

// You can get a string of the current date using Date as a function:
let nowStr = Date();
console.log(nowStr); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)'
```

It is currently possible to implement something like that using [new.target](http://mdn.io/new.target) (see [example in proposal](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md#motivating-example)) and this new feature makes it available for ES2015 classes.

A date implementation could be:

```js
class Date {
  constructor() {
    // ...
  }

  call constructor() {
    let date = new Date();
    return date.toString();
  }
}

let now = new Date(); // Get a Date instance
let nowStr = Date(); // Use the 'call constructor()' part to get a string value of the current date
```

## Installation

```sh
npm install --save-dev babel-plugin-transform-class-constructor-call
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": ["transform-class-constructor-call"]
}
```

### Via CLI

```sh
babel --plugins transform-class-constructor-call script.js
```

### Via Node API

```javascript
require("babel-core").transform("code", {
  plugins: ["transform-class-constructor-call"]
});
```

## References

* [Inactive Proposals](https://github.com/tc39/proposals/blob/master/inactive-proposals.md)
* [Proposal: Call Constructor](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md)
* [Blog post: ECMAScript proposal: function-callable classes](http://www.2ality.com/2015/10/call-constructor-esprop.html)

---
_Source: https://npm.io/package/babel-plugin-transform-class-constructor-call · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
