回答編集履歴
8
background: yellow;
test
CHANGED
@@ -176,7 +176,7 @@
|
|
176
176
|
|
177
177
|
.c {
|
178
178
|
|
179
|
-
background: yello;
|
179
|
+
background: yellow;
|
180
180
|
|
181
181
|
}
|
182
182
|
|
7
d
test
CHANGED
@@ -182,7 +182,7 @@
|
|
182
182
|
|
183
183
|
|
184
184
|
|
185
|
-
.
|
185
|
+
.d {
|
186
186
|
|
187
187
|
background: green;
|
188
188
|
|
6
a
test
CHANGED
@@ -123,3 +123,121 @@
|
|
123
123
|
console.log(hoge.next().value) //b
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# 追記 (使い方のイメージ)
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
[https://codepen.io/anon/pen/aYgKgz
|
136
|
+
|
137
|
+
](https://codepen.io/anon/pen/aYgKgz)
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
<div id='target' class=''></div>
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
#target {
|
150
|
+
|
151
|
+
width: 100px;
|
152
|
+
|
153
|
+
height: 100px;
|
154
|
+
|
155
|
+
border: solid 1px #000000;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
.a {
|
162
|
+
|
163
|
+
background: red;
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
.b {
|
170
|
+
|
171
|
+
background: blue;
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
.c {
|
178
|
+
|
179
|
+
background: yello;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
.c {
|
186
|
+
|
187
|
+
background: green;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
function foo(list) {
|
198
|
+
|
199
|
+
var i = 0;
|
200
|
+
|
201
|
+
var max = list.length;
|
202
|
+
|
203
|
+
return function baz() {
|
204
|
+
|
205
|
+
if (i >= max) {
|
206
|
+
|
207
|
+
i = 0;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
return list[i++];
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
const hoge = foo(['a', 'b', 'c', 'd']);
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
var $target = document.getElementById('target');
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
$target.addEventListener('mousedown',function(){
|
230
|
+
|
231
|
+
this.className = hoge();
|
232
|
+
|
233
|
+
});
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
$target.addEventListener('mouseup',function(){
|
238
|
+
|
239
|
+
this.className = hoge();
|
240
|
+
|
241
|
+
});
|
242
|
+
|
243
|
+
```
|
5
lazexさんのコメントを反映
test
CHANGED
@@ -62,15 +62,11 @@
|
|
62
62
|
|
63
63
|
const max = list.length;
|
64
64
|
|
65
|
-
|
66
|
-
|
67
65
|
while (i < max) {
|
68
66
|
|
69
67
|
yield list[i++];
|
70
68
|
|
71
69
|
}
|
72
|
-
|
73
|
-
|
74
70
|
|
75
71
|
yield* foo(list);
|
76
72
|
|
@@ -93,3 +89,37 @@
|
|
93
89
|
console.log(hoge.next().value) //b
|
94
90
|
|
95
91
|
```
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
## lazexさんからコメント欄で頂いたコード
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
function* foo(list) {
|
100
|
+
|
101
|
+
while(true) {
|
102
|
+
|
103
|
+
yield* list;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
const hoge = foo(['a', 'b', 'c', 'd']);
|
112
|
+
|
113
|
+
console.log(hoge.next().value) //a
|
114
|
+
|
115
|
+
console.log(hoge.next().value) //b
|
116
|
+
|
117
|
+
console.log(hoge.next().value) //c
|
118
|
+
|
119
|
+
console.log(hoge.next().value) //d
|
120
|
+
|
121
|
+
console.log(hoge.next().value) //a
|
122
|
+
|
123
|
+
console.log(hoge.next().value) //b
|
124
|
+
|
125
|
+
```
|
4
a
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
質問を読み間違えている可能性はありますが、とりあえず呼び出される度に次のクラス名を返してくれるようなものがあれば良いのかなと思ったので簡易的なものを書いてみました。
|
45
|
+
質問を読み間違えている可能性はありますが、少なくとも「このデザインのa1~a4をボタンを押すごとに順に進むようにしたいです。」の行までの説明を読む限りでは、とりあえず呼び出される度に次のクラス名を返してくれるようなものがあれば良いのかなと思ったので簡易的なものを書いてみました。
|
46
46
|
|
47
47
|
|
48
48
|
|
3
最後のgeneratorのログ出力のコメントが間違ってたので、そこを修正
test
CHANGED
@@ -88,8 +88,8 @@
|
|
88
88
|
|
89
89
|
console.log(hoge.next().value) //d
|
90
90
|
|
91
|
-
console.log(hoge.next().value) //
|
91
|
+
console.log(hoge.next().value) //a
|
92
92
|
|
93
|
-
console.log(hoge.next().value) //
|
93
|
+
console.log(hoge.next().value) //b
|
94
94
|
|
95
95
|
```
|
2
a
test
CHANGED
@@ -78,18 +78,18 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
const
|
81
|
+
const hoge = foo(['a', 'b', 'c', 'd']);
|
82
82
|
|
83
|
-
console.log(
|
83
|
+
console.log(hoge.next().value) //a
|
84
84
|
|
85
|
-
console.log(
|
85
|
+
console.log(hoge.next().value) //b
|
86
86
|
|
87
|
-
console.log(
|
87
|
+
console.log(hoge.next().value) //c
|
88
88
|
|
89
|
-
console.log(
|
89
|
+
console.log(hoge.next().value) //d
|
90
90
|
|
91
|
-
console.log(
|
91
|
+
console.log(hoge.next().value) //e
|
92
92
|
|
93
|
-
console.log(
|
93
|
+
console.log(hoge.next().value) //f
|
94
94
|
|
95
95
|
```
|
1
a
test
CHANGED
@@ -46,4 +46,50 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
関数や変数の命名は適当につけましたが、あとはhoge関数をmousedownやmouseupの度に呼んであげればよいの
|
49
|
+
関数や変数の命名は適当につけましたが、あとはhoge関数をmousedownやmouseupの度に呼んであげればよいのかなと。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# ES6対応OKな場合
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
function* foo(list) {
|
60
|
+
|
61
|
+
let i = 0;
|
62
|
+
|
63
|
+
const max = list.length;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
while (i < max) {
|
68
|
+
|
69
|
+
yield list[i++];
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
yield* foo(list);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
const f = foo(['a', 'b', 'c', 'd']);
|
82
|
+
|
83
|
+
console.log(f.next().value) //a
|
84
|
+
|
85
|
+
console.log(f.next().value) //b
|
86
|
+
|
87
|
+
console.log(f.next().value) //c
|
88
|
+
|
89
|
+
console.log(f.next().value) //d
|
90
|
+
|
91
|
+
console.log(f.next().value) //e
|
92
|
+
|
93
|
+
console.log(f.next().value) //f
|
94
|
+
|
95
|
+
```
|