es6-test.js
858 Bytes
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
class Animal {
constructor() {
this.type = 'animal';
}
says(say = 'hi') {
setTimeout(() => {
console.log(`${this.type} says ${say}`);
}, 1000);
}
}
class Cat extends Animal {
constructor() {
super();
this.type = 'cat';
}
setInfo(info) {
let {name, age, color} = info;
name && (this.name = name);
age && (this.age = age);
color && (this.color = color);
}
infos() {
console.log(this);
}
}
const timeout = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
function* generator() {
yield 'hello';
yield 'generator';
}
let cat = new Cat();
cat.says();
cat.setInfo({name: 'mini', color: 'black'});
cat.infos();
console.log([...generator()]);
export {
cat,
timeout
};