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;
}