با این ابزار میتوانید کدهای JavaScript خود را اعتبارسنجی، فرمتدهی، فشردهسازی و بین نسخههای ES5 و ES6 تبدیل کنید.
توجه: این ابزار از کتابخانه Babel برای تبدیل بین ES5 و ES6 استفاده میکند و قادر به تبدیل اکثر ویژگیهای جدید JavaScript است.
ES6 (ECMAScript 2015) ویژگیهای جدیدی به JavaScript اضافه کرده است:
(params) => { statements }`string ${variable}`const { a, b } = obj;...// ES5 Example
var numbers = [1, 2, 3, 4, 5];
var doubled = [];
for (var i = 0; i < numbers.length; i++) {
doubled.push(numbers[i] * 2);
}
function greet(name) {
return "Hello, " + name + "!";
}
var formatNumber = function(num) {
return num.toFixed(2);
};
var user = {
name: "John",
age: 30,
sayHello: function() {
var self = this;
setTimeout(function() {
console.log(self.name + " says hello!");
}, 1000);
}
};
// Constructor function
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.greet = function() {
return "Hi, I'm " + this.name;
};
// Create a new instance
var john = new Person("John", 30);// ES6 Example
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(num => num * 2);
const greet = name => `Hello, ${name}!`;
const formatNumber = num => num.toFixed(2);
const user = {
name: "John",
age: 30,
sayHello() {
setTimeout(() => {
console.log(`${this.name} says hello!`);
}, 1000);
}
};
// Destructuring
const { name, age } = user;
// Spread operator
const newArray = [...numbers, 6, 7, 8];
// Default parameters
function multiply(a, b = 1) {
return a * b;
}
// Classes
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hi, I'm ${this.name}`;
}
}
// Create a new instance
const john = new Person("John", 30);
// Async/await example
async function fetchData() {
try {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
return data;
} catch (error) {
console.error('Error:', error);
}
}