swc_ecma_compat_es2015

Function arrow

source
pub fn arrow(unresolved_mark: Mark) -> impl Pass + VisitMut + InjectVars
Expand description

Compile ES2015 arrow functions to ES5

§Example

§In

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

 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());