Skip to content

Commit 8e7f871

Browse files
committed
ES6 feature sample code
1 parent 75138b5 commit 8e7f871

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

days/041-044-react/es6/arrow.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// if single line, omit return and {}
2+
const myFunc = (name='stranger') => 'Hello ' + name;
3+
4+
console.log(myFunc());
5+
console.log(myFunc('mike'));

days/041-044-react/es6/class.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Bite {
2+
3+
constructor(title, points){
4+
this.title = title;
5+
this.points = points;
6+
}
7+
8+
str(){
9+
return 'Bite: ' + this.title + ' (' + this.points + ' pt.)';
10+
}
11+
}
12+
13+
if (require.main === module) {
14+
bite1 = new Bite('sum of numbers', 2)
15+
console.log(bite1.str())
16+
17+
bite2 = new Bite('parse list of names', 3)
18+
console.log(bite2.str())
19+
}
20+
21+
module.exports = Bite;

days/041-044-react/es6/destruct.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const bite = {
2+
id: 1,
3+
title: 'sum of numbers',
4+
level: 'beginner',
5+
points: 3,
6+
}
7+
8+
// destructure bite object
9+
const { id, title, level, points } = bite;
10+
console.log(id);
11+
console.log(title);
12+
console.log(level);
13+
console.log(points);

days/041-044-react/es6/hello.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { Component } from 'react';
2+
3+
class App extends Component {
4+
5+
render(){
6+
const hello = 'Hello world from React';
7+
return (
8+
<h1>{hello}</h1>
9+
)
10+
}
11+
}

days/041-044-react/es6/inherit.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Bite = require('./class.js');
2+
3+
class EnterpriseBite extends Bite {
4+
str(){
5+
return 'EP ' + super.str();
6+
}
7+
}
8+
9+
let bite = new EnterpriseBite('hangman', 4);
10+
11+
console.log(bite.title);
12+
console.log(bite.str());

days/041-044-react/es6/mapfilter.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const ninjas = [
2+
{ name: 'martin', points: 225 },
3+
{ name: 'mike', points: 200 },
4+
{ name: 'dirk', points: 175 },
5+
];
6+
7+
console.log(
8+
ninjas
9+
.filter(ninja => ninja.points >= 200)
10+
.map(ninja => `<li>${ninja.name}</li>`)
11+
)

0 commit comments

Comments
 (0)