Last active
February 10, 2016 02:19
-
-
Save gartenfeld/c8f6c1ffe46828286fb7 to your computer and use it in GitHub Desktop.
Extends the global window with Lodash's debounce method
This file contains hidden or 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
!function(){function t(t,e,r){function a(){b&&clearTimeout(b),v&&clearTimeout(v),x=0,s=v=g=b=w=void 0}function u(e,n){n&&clearTimeout(n),v=b=w=void 0,e&&(x=T(),m=t.apply(g,s),b||v||(s=g=void 0))}function c(){var t=e-(T()-d);0>=t||t>e?u(w,v):b=setTimeout(c,t)}function f(){return(b&&w||v&&$)&&(m=t.apply(g,s)),a(),m}function l(){u($,b)}function p(){s=arguments,d=T(),g=this,w=$&&(b||!h);var n=!1,i=!1;if(j===!1)n=h&&!b;else{v||h||(x=d);var o=j-(d-x);i=0>=o||o>j,i?(v&&(v=clearTimeout(v)),x=d,m=t.apply(g,s)):v||(v=setTimeout(l,o))}return i&&b?b=clearTimeout(b):b||e===j||(b=setTimeout(c,e)),n&&(i=!0,m=t.apply(g,s)),!i||b||v||(s=g=void 0),m}var s,v,m,d,g,b,w,x=0,h=!1,j=!1,$=!0;if("function"!=typeof t)throw new TypeError(o);return e=i(e)||0,n(r)&&(h=!!r.leading,j="maxWait"in r&&y(i(r.maxWait)||0,e),$="trailing"in r?!!r.trailing:$),p.cancel=a,p.flush=f,p}function e(t){var e=n(t)?m.call(t):"";return e==a||e==u}function n(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function i(t){if(n(t)){var i=e(t.valueOf)?t.valueOf():t;t=n(i)?i+"":i}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(c,"");var o=l.test(t);return o||p.test(t)?s(t.slice(2),o?2:8):f.test(t)?r:+t}var o="Expected a function",r=NaN,a="[object Function]",u="[object GeneratorFunction]",c=/^\s+|\s+$/g,f=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,p=/^0o[0-7]+$/i,s=parseInt,v=Object.prototype,m=v.toString,y=Math.max,T=Date.now;window.debounce=t}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment