# babel-plugin-generator-bind-this

Latest version **0.1.2** (published 2020-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-generator-bind-this
pnpm add babel-plugin-generator-bind-this
yarn add babel-plugin-generator-bind-this
bun add babel-plugin-generator-bind-this
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2020-09-09 |
| First published | 2020-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matthew5 |
| Maintainers | matthew5 |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-generator-bind-this
- Repository: https://github.com/matthew5-library/babel-plugin-generator-bind-this
- Homepage: https://github.com/matthew5-library/babel-plugin-generator-bind-this#readme
- Issues: https://github.com/matthew5-library/babel-plugin-generator-bind-this/issues
- npm.io page: https://npm.io/package/babel-plugin-generator-bind-this

## Recent versions

- 0.1.2 (latest) — 2020-09-09
- 0.1.1 — 2020-09-09
- 0.1.0 — 2020-09-09

## README

### Usage

1. `yarn add babel-plugin-generator-bind-this -D`

2. activate in .babelrc

```json
{
  "plugins": ["babel-plugin-generator-bind-this"]
}
```

### Why

1. generator cannot use arrow-function
2. check the special case below:  
   in this case the generator in `result1` cannot get class property `bindValue` `"class value"`, but got `"scope value"`, and result2 can get `"class value"`
3. `generator.bind(this)` by yourself or automatically by this plugin

```js
const doSomething = (method) => {
  return {
    bindValue: 'scope value',
    method
  }
}

class Base {}

class Test extends Base {
  bindValue = 'class value'
  result1 = doSomething(function* (param) {
    console.log(param, this.bindValue)
  })

  result2 = doSomething(
    function* (param) {
      console.log(param, this.bindValue)
    }.bind(this)
  )
}

const ins = new Test()
ins.result1.method('case1').next()
ins.result2.method('case2').next()
```

### Demo

`yarn transform`, check the output in `transform/output.js`

---
_Source: https://npm.io/package/babel-plugin-generator-bind-this · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
