//
function debounce(func, wait, immediate)
{
var timeout;
return function(){
//确保this指向不变
var that = this;
//确保能显示传递的事件元素
var args = arguments;
if(timeout)cleatTimeOut(timeout)
//immediate是否立即触发, 然后事件停止后N秒才能再触发
还是直接事件停止后N秒才能触发
if(immediate)
{
timeout = Settimeout(function(){timeout = null}, wait)
if(!timeout){
func.apply((that, args), wait);
}
}
else{
timeout = Settimeout(func.apply(that, arsg), wait);
}
}
}