Skip to content

Instantly share code, notes, and snippets.

View hereisfun's full-sized avatar

calvinfung hereisfun

View GitHub Profile
@hereisfun
hereisfun / throttle.js
Created March 13, 2017 12:55
节流函数,保证某一操作的最小时间间隔
//fn为要节流的操作,interval为最小操作间隔
var throttle = function(fn, interval){
var timer,
_fn = fn;//保存要延时的函数的引用
return function(){
var that = this;
var arg = arguments;
//如果有未完成的计时器,则不进行操作
@hereisfun
hereisfun / timechunk.js
Last active March 13, 2017 12:31
分时函数,将一次性大批量的操作分割成多次小批量
//ary为要批量处理的数据,fn为对每个数据的操作方式,count为每次处理的量
var timechunk = function(ary, fn, count){
var obj,
timer;
var start = function(){
for(var i = 0; i < count; i++){
if(ary.length === 0){
return;
}
obj = ary.shift();