Last active
March 3, 2016 21:12
-
-
Save Kuzcoo/0cf205a8142f4db01b2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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