function debounce(func, wait, immediate) {
        var timeout;
        return function () {
            var args = arguments,
                callNow = immediate && !timeout,
                later = function () {
                    timeout = null;
                    if (!immediate) {
                        func.apply(window, args);
                    }
                };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) {
                func.apply(window, args);
            }
        };
    }
// If `immediate` is passed, trigger the function on the leading edge, instead of the trailing.
If `immediate` is passed, trigger the function on the leading edge, instead of the trailing.
If ` immediate ` is passed trigger the function on the leading edge instead of the trailing .
function debounce(func, wait, immediate) {
        var timeout;
        return function () {
            var args = arguments,
                callNow = immediate && !timeout,
                later = function () {
                    timeout = null;
                    if (!immediate) {
                        func.apply(window, args);
                    }
                };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) {
                func.apply(window, args);
            }
        };
    }
function debounce ( func , wait , immediate ) { var timeout ; return function ( ) { var args = arguments , callNow = immediate && ! timeout , later = function ( ) { timeout = null ; if ( ! immediate ) { func . apply ( window , args ) ; } } ; clearTimeout ( timeout ) ; timeout = setTimeout ( later , wait ) ; if ( callNow ) { func . apply ( window , args ) ; } } ; }
If `immediate` is passed, trigger the function on the leading edge, instead of the trailing.
If ` immediate ` is passed trigger the function on the leading edge instead of the trailing .