xto6.js - від es5 до es6

Оригінал

xto6.js всупереч більшості подібних бібліотек транслює ваш es5 код в зрозумілий es6 код.

До:

var Person = function () {
  console.log('This is the constructor.');
};
Person.prototype.getAge = function (birthYear) {
  var age = 2015;
  age -= birthYear;
  return result;
};
Object.defineProperty(Person.prototype, 'age', {
  get: function () {
    return this.getAge();
  }
});
var personsUtils = {
  getName: function (person) {
    return person.firstname + ' ' + person.lastname;
  },
  logInformation: function (person) {
    var message = 'You are ' + person.age;
    console.log(message);
  }
};
setTimeout(function() {
    alert('Having some fun !');
});

Після:

class Person {
    constructor() {
        console.log('This is the constructor.');
    }
    getAge(birthYear) {
        let age = 2015;
        age -= birthYear;
        return result;
    }
    get age() {
        return this.getAge();
    }
}
const personsUtils = {
    getName(person) {
        return `${ person.firstname } ${ person.lastname }`;
    },
    logInformation(person) {
        const message = `You are ${ person.age }`;
        console.log(message);
    }
};
setTimeout(() => {
    alert('Having some fun !');
});

Авторизуйтесь, щоб залишити коментар.