@babel/plugin-transform-arrow-functions
信息
This plugin is included in @babel/preset-env
Example
In
JavaScript
var a = () => {};
var a = b => b;
const double = [1, 2, 3].map(num => num * 2);
console.log(double); // [2,4,6]
var bob = {
_name: "Bob",
_friends: ["Sally", "Tom"],
printFriends() {
this._friends.forEach(f => console.log(this._name + " knows " + f));
},
};
console.log(bob.printFriends());
Out
JavaScript
var a = function() {};
var a = function(b) {
return b;
};
const double = [1, 2, 3].map(function(num) {
return num * 2;
});
console.log(double); // [2,4,6]
var bob = {
_name: "Bob",
_friends: ["Sally", "Tom"],
printFriends() {
var _this = this;
this._friends.forEach(function(f) {
return console.log(_this._name + " knows " + f);
});
},
};
console.log(bob.printFriends());
Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-arrow-functions
yarn add --dev @babel/plugin-transform-arrow-functions
pnpm add --save-dev @babel/plugin-transform-arrow-functions
Usage
With a configuration file (Recommended)
Without options:
babel.config.json
{
"plugins": ["@babel/plugin-transform-arrow-functions"]
}
With options:
babel.config.json
{
"plugins": [["@babel/plugin-transform-arrow-functions", { "spec": true }]]
}
Via CLI
Shell
babel --plugins @babel/plugin-transform-arrow-functions script.js