Refactor move docs (#8108)
* feat: [skip] generate readme script * docs: [skip ci] update READMEs * docs: [skip ci] fix code block type * chore: [skip ci] move generator script
This commit is contained in:
@@ -1,62 +1,19 @@
|
||||
# @babel/plugin-transform-instanceof
|
||||
|
||||
> Wraps `instanceof` expressions to allow constructors to customize the logic with a `Symbol.hasInstance` method
|
||||
> This plugin transforms all the ES2015 'instanceof' methods
|
||||
|
||||
## Example
|
||||
See our website [@babel/plugin-transform-instanceof](https://new.babeljs.io/docs/en/next/babel-plugin-transform-instanceof.html) for more information.
|
||||
|
||||
**In**
|
||||
## Install
|
||||
|
||||
```javascript
|
||||
foo instanceof Bar;
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
function _instanceof(left, right) {
|
||||
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
||||
return right[Symbol.hasInstance](left);
|
||||
} else {
|
||||
return left instanceof right;
|
||||
}
|
||||
}
|
||||
|
||||
_instanceof(foo, Bar);
|
||||
```
|
||||
|
||||
## Installation
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-instanceof
|
||||
npm install --save @babel/plugin-transform-instanceof
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@babel/plugin-transform-instanceof"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
babel --plugins @babel/plugin-transform-instanceof script.js
|
||||
yarn add --save @babel/plugin-transform-instanceof
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["@babel/plugin-transform-instanceof"]
|
||||
});
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [ES6 Spec: InstanceOf Operator Semantics](https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator)
|
||||
* [MDN: Symbol.hasInstance](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
|
||||
|
||||
Reference in New Issue
Block a user