351
132

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

"何回閉じても無駄ですよ〜"と無限にアラートを出す10の方法

Last updated at Posted at 2019-03-04

掲示板に書き込むと補導または書類送検されるので気をつけてください

while

これは定番ですね。

while(1) alert('何回閉じても無駄ですよ〜')

for

for(;;) alert('何回閉じても無駄ですよ〜')

setInterval

setInterval(() => alert('何回閉じても無駄ですよ〜'))

alertだけでよければ、以下でも実行できます。

setInterval(alert)

setTimeout

function f() {
  alert('何回閉じても無駄ですよ〜')
  setTimeout(f)
}
setTimeout(f)

setImmediate

function f() {
  alert('何回閉じても無駄ですよ〜')
  setImmediate(f)
}
setImmediate(f)

queueMicrotask

function f() {
  alert('何回閉じても無駄ですよ〜')
  queueMicrotask(f)
}
queueMicrotask(f)

requestAnimationFrame

function f() {
  alert('何回閉じても無駄ですよ〜')
  requestAnimationFrame(f)
}
requestAnimationFrame(f)

requestIdleCallback

function callback() {
  alert('何回閉じても無駄ですよ〜')
  requestIdleCallback(callback)
}
requestIdleCallback(callback)

再帰関数(Recursive function)

function f() {
  alert('何回閉じても無駄ですよ〜')
  f()
}
f()

toString

({ toString(){ alert('何回閉じても無駄ですよ〜')+this }})+''

getter

({
  get m() { return alert('何回閉じても無駄ですよ〜')||this.m }
}).m

setter

({
  set m(msg) { this.m = alert(msg)||msg }
}).m = '何回閉じても無駄ですよ〜'

内部DSL(Internal Domain Specific Language)

import('./何回閉じても無駄ですよ.js')
  .then(({何回閉じても無駄ですよ}) => 何回閉じても無駄ですよ())

See the Pen 何回閉じても無駄ですよ〜 by John Doe (@04) on CodePen.

イテレータ

var iterable = {
  [Symbol.iterator]() {
    return {
      next() {
        return { done: false }
      }
    }
  }
}
for(var value of iterable) alert('何回閉じても無駄ですよ〜')

配列

const a = [0]
for (const v of a) a.push(alert('何回閉じても無駄ですよ〜'))

おや、誰か来たようだ...

351
132
14

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
351
132

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?