@babel/plugin-transform-instanceof

Example

In

JavaScript

  1. foo instanceof Bar;

Out

JavaScript

  1. function _instanceof(left, right) {
  2. if (
  3. right != null &&
  4. typeof Symbol !== "undefined" &&
  5. right[Symbol.hasInstance]
  6. ) {
  7. return right[Symbol.hasInstance](left);
  8. } else {
  9. return left instanceof right;
  10. }
  11. }
  12. _instanceof(foo, Bar);

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install --save-dev @babel/plugin-transform-instanceof
  1. yarn add --dev @babel/plugin-transform-instanceof
  1. pnpm add --save-dev @babel/plugin-transform-instanceof

Usage

babel.config.json

  1. {
  2. "plugins": ["@babel/plugin-transform-instanceof"]
  3. }

Via CLI

Shell

  1. babel --plugins @babel/plugin-transform-instanceof script.js

Via Node API

JavaScript

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-instanceof"],
  3. });

References