![javascript编程 javascript编程](https://i-blog.csdnimg.cn/blog_migrate/dd60aeccd75fc3367e4cf8eec4549b4c.png)
代码展示
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"