Is there any other way to implement a “listening” function without an infinite while loop?

I’ve written the answer to this question as an aside in another answer. Normally I’d close this question as a duplicate and point to that answer however this is a very different question. The other question asked about javascript performance. In order to answer that I had to first write the answer to this question. … Read more