@babel/plugin-transform-instanceof
示例
输入
JavaScript
foo instanceof Bar;
输出
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);
安装
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-instanceof
yarn add --dev @babel/plugin-transform-instanceof
pnpm add --save-dev @babel/plugin-transform-instanceof
用法
使用配置文件(推荐)
babel.config.json
{
"plugins": ["@babel/plugin-transform-instanceof"]
}
通过 CLI
Shell
babel --plugins @babel/plugin-transform-instanceof script.js
通过 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-instanceof"],
});