var timerId, n, flag, r = function(a) {alert(a)}; function em(a) { flag ? n = a : (r(a), n = !1, flag = !0, timerId = setTimeout(function () { flag = !1; n && em(n) }, 5000)) }; em(1); em(2);