もっといい書き方はないものか。メモ
複数ダイアログがぽんぽん開くようなWebアプリでWindowの初期表示位置がずれていくタイプのやつ。
初期表示位置を算出するいい方法はないかな
イメージは↓
class positionGenarator { constructor(x, y) { this.x = x; this.y = y; this.originX = x; this.originY = y; this.count = 0; } next() { const resultX = this.x; const resultY = this.y; this.count = this.count + 1; if (this.count % 5 === 0 && this.count % 10 !== 0) { this.y = this.originY; this.x = this.x + 24; } else if (this.count % 10 === 0) { this.x = this.originX; this.y = this.originY; } else { this.x = this.x + 24; this.y = this.y + 24; } return { x: resultX, y: resultY}; } }
const a = new positionGenarator(1000, 500); a.next() // -> {x: 1000, y: 500} a.next() // -> {x: 1024, y: 524} a.next() // -> {x: 1048, y: 548} a.next() // -> {x: 1072, y: 572} a.next() // -> {x: 1096, y: 596} a.next() // -> {x: 1120, y: 500} a.next() // -> {x: 1144, y: 524} a.next() // -> {x: 1168, y: 548} a.next() // -> {x: 1192, y: 572} a.next() // -> {x: 1216, y: 596} a.next() // -> {x: 1000, y: 500} ここで最初に戻る
generatorを使って書いた方がスマートかと思ったが、いつまでのdoneがtrueにならないgeneratorってなにか気持ち悪いのかな?