Detecting multi-clicks

Suppose you decided, for some reason or another, that users should be able to triple-click or four-click on something, and the number of clicks would somehow be meaningful and produce some kind of special result. Browsers do very well detecting single- or double-clicks and let you respond to them, but triple- (or more) clicks aren't available so easily. However, we can make do with a bit of FRP. Let's start with a really basic layout, including a text span that the user should click. The code is given here:

<html>  <head>    <title>Multiple click example</title>    <script type="text/javascript" src="rxjs.umd.js"></script>  </head>  <body>    <span id="mySpan">Click this text many times (quickly)</span>    <script>      // our code goes ...

Get Mastering JavaScript Functional Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.