/**
 * 添加函数返回值
 */

// 第五版
function debounce(func, wait, immediate) {

    var timeout, result;

    return function () {
        var context = this;
        var args = arguments;

        if (timeout) clearTimeout(timeout);
        if (immediate) {
            // 如果已经执行过，不再执行
            var callNow = !timeout;
            timeout = setTimeout(function(){
                timeout = null;
            }, wait)
            if (callNow) result = func.apply(context, args)
        }
        else {
            timeout = setTimeout(function(){
                func.apply(context, args)
            }, wait);
        }
        return result;
    }
}

var count = 1;
var container = document.getElementById('container');

function getUserAction() {
    container.innerHTML = count++;
    return '111'
};

container.onmousemove = function(){
    var result = debounce(getUserAction, 1000, true)();
    console.log(result)
}
@@ -794,16 +794,65 @@
 11'%0A%7D;%0A%0A
+var result = debounce(getUserAction, 1000, true)%0A
 containe
@@ -894,49 +894,17 @@
  res
-ult = debounce(getUserAction, 1000, true)
+ = result
 ();%0A
@@ -922,14 +922,11 @@
 .log(res
-ult
 )%0A%7D

修订 debounce6.js