Skip to content

Instantly share code, notes, and snippets.

@Kuzcoo
Last active March 3, 2016 21:12
Show Gist options
  • Save Kuzcoo/0cf205a8142f4db01b2b to your computer and use it in GitHub Desktop.
Save Kuzcoo/0cf205a8142f4db01b2b to your computer and use it in GitHub Desktop.
let debounce = function (eventName, time, fn) {
// locker
let locker = function () {
let isLocked = false;
let unlock = function (boolLock, fn) {
setTimeout(function () {
isLocked = false;
fn();
},time);
};
return {
lock(fn) {
fn();
unlock(isLocked, fn);
return isLocked = true;
},
isLocked() { return isLocked; }
};
}();
//
let {isLocked, lock} = locker;
window.addEventListener(eventName, function () {
if (!isLocked()) { return lock(fn); }
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment