Function:
function throttle(fn,ms) {
var last = (new Date()).getTime();
return (function() {
var now = (new Date()).getTime();
if (now - last > ms) {
last = now;
fn.apply(this, arguments);
}
});
}
parameters fn: Incoming function/method
Parameter ms: The interval (in milliseconds) between each function call. If you enter 2000, the function will not be triggered repeatedly within 2 seconds.
Attached is an initialization example
document.getElementById('pop').onclick = throttle(function (){
alert(this.id);
},2000)
scope setting For the caller itself
fn.apply(this, arguments);
Examples
]