loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//ES5
var collection = {
  items: [],
  add: function (...items) {
    this.items.push(...items);
  },
  get: function (index) {
    return this.items[index];
  }
};

//ES6
var list = {
  items: [],
  add(...items) {
    this.items.push(...items);
  },
  get(index) {
    return this.items[index];
  }
};

//method definition in class in ES6
class EnglishGreeting {
  constructor(name) {
    this.name = name;
  }
  getMessage() {
    return 'Hello ' + this.name;
  }
}

//ES6 - Computed property names and methods
const addMethod = 'add',
  getMethod = 'get';
const personCollection = {
  items: [],
  [addMethod](...items) {
    this.items.push(...items);
  },
  [getMethod](index) {
    return this.items[index];
  }
};





var englishGreeting = new EnglishGreeting('Kenan Hancer');
console.log(englishGreeting.getMessage()); // 'Hello Kenan Hancer'

collection.add('Banana', 'Lemon', 'Orange');
console.log(collection.get(1)); // 'Lemon'

list.add('Banana', 'Lemon', 'Orange');
console.log(list.get(1)); // 'Lemon'

personCollection[addMethod]('Banana', 'Lemon', 'Orange');
console.log(personCollection[getMethod](1)); // 'Lemon'
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie