By Andrea Stagi, full-stack deveLover @ Nephila
http://babeljs.io/
const input = [1, 2, 3];
console.log(
input.map(item => item + 1)
);
var input = [1, 2, 3];
console.log(input.map(
function (item) {
return item + 1;
}
));
TRANSPILE
class Person {
constructor(firstName, lastName, age=18) {
this._firstName = firstName;
this._lastName = lastName;
this._age = age;
}
getIdentityCard() {
// ....
}
}
class FriendlyGuy extends Person {
constructor(firstName, lastName, age=18) {
super(firstName, lastName, age);
this._friends = [];
}
getIdentityCard() {
// ....
}
addFriend(friend) {
// ....
}
}
// .....
pullEar() {
let that = this;
var pullEarActions = {
[Symbol.iterator]: function*() {
for (let i = 1; i <= that._age; i++) {
yield i;
}
}
};
return pullEarActions;
}
// .....
npm install babel --save-dev
<script src="node_modules/babel/polyfill.js">
</script>
OR USING MODULES IMPORT... (COMING SOON)
console.log(`I am ${this._firstName} !`);
// ......
showFriends() {
this._friends.forEach(f =>
console.log(
// Use this._firstName and
// f._firstName
)
);
}
// .......
// .....
getIdentityCard() {
let name = this._firstName;
name += ' ' + this._lastName;
let age = this._age;
return {name, age}
}
// .....
export class Person {
// .....
}
person.es6.js
import {Person} from './person.es6';
import '../node_modules/babel/polyfill'
export class FriendlyGuy extends Person {
// ....
}
friendlyguy.es6.js
import {FriendlyGuy} from './friendlyguy.es6';
export function main() {
let andrea = new FriendlyGuy('Andrea', 'Stagi', 28);
let mark = new FriendlyGuy('Mark', 'Iozz', 27);
let matt = new FriendlyGuy('Matt', 'Lap', 29);
andrea.addFriend(mark);
andrea.addFriend(mark);
andrea.showFriends();
mark.showFriends();
for (var age of andrea.pullEar()) {
// truncate the sequence at 15
if (age == 15) {
break;
}
console.log(`${age}!!`);
}
console.log(mark.getIdentityCard());
}
window.main = main;
https://github.com/DjangoBeer/es6samples/blob/master/gulpfile.js