代碼展現
function throttle(fn,time){
var startTime = new Date();
return function(){
var time_ = (new Date() - startTime) >= time;
if(time_){
fn.apply(this);
startTime = new Date();
}
}
}
function fn(){
console.log("觸發了事件");
}
window.onscroll = throttle(fn,1000);
function makeUniqueStringFunction(start) {
var COUNTER = start;
return function(prefix) {
return [prefix, COUNTER++].join('');
}
};
var uniqueString = makeUniqueStringFunction(0);
uniqueString("dari");
//=> "dari0"
uniqueString("dari");
//=> "dari1"