@babel/plugin-transform-instanceof

NOTE: This plugin is included in @babel/preset-env

Example

In

  1. foo instanceof Bar;

Out

  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

  1. npm install --save-dev @babel/plugin-transform-instanceof

Usage

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

Via CLI

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

Via Node API

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

References