Skip to main content

@babel/plugin-transform-instanceof

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

Example

In

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

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

Usage

babel.config.json
{
"plugins": ["@babel/plugin-transform-instanceof"]
}

Via CLI

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

Via Node API

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

References