-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerators.html
74 lines (55 loc) · 1.91 KB
/
generators.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<!-- Load babel 5 - babel-core -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script>
<!-- Load Babel Polyfill -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.js"></script>
<script type="text/babel">
function* director(){
yield "Three";
yield "Two";
yield "One";
yield "Action";
}
var action = director();
// Use .next() function to restart the action
console.log(action.next().value);
console.log(action.next().value);
console.log(action.next().value);
console.log(action.next().value);
console.log(action.next().value);
// Sort of timer
function* eachItem(arr) {
for (var i = 0; i< arr.length; i++) {
yield arr[i];
}
}
// Pass array to a variable
var letters = eachItem(["a", "b", "c", "d", "e", "f", "g"]);
// set interval as 500 millionsec
var abcs = setInterval(function(){
// Move to next yield.
var letter = letters.next();
if (letter.done) {
clearInterval(abcs);
console.log("Now I'm done.");
}else {
console.log(letter.value);
}
}, 500);
</script>
<title>Generators</title>
</head>
<body>
<h1>Hit the pit</h1>
<h2>Generators</h2>
<ul>
<li>import babel-polyfill library</li>
<li>function* name(){
yield "alert";
}
</li>
</ul>
</body>
</html>