SOURCE

console 命令行工具 X clear

                    
>
console
// 函数节流
var processor = {
    timeoutId: null,
    // 实际进行处理的方法
    performProcessing: function () {
        console.log('实际执行的代码?')
    },
    process: function () {
        clearTimeout(this.timeoutId)
        var that = this
        this.timeoutId = setTimeout(function () {
            that.performProcessing()
        }, 100)
    }
}

function throttle(method, context) {
    clearTimeout(method.tId)
    method.tId = setTimeout(function () {
        method.call(context)
    }, 200)
}

resizeDiv = function () {
    console.log('俺执行了')
    var div = document.getElementById('myDiv')
    div.style.height = div.offsetWidth + 'px'
}

window.onresize = function () {
    throttle(resizeDiv, window)
}

<div id="myDiv"></div>
#myDiv{
    width: 100%;
    height: 200px;
    background-color: #cdcdcd;
}