An implementation of hysteresis in JavaScript