Skip to content

Instantly share code, notes, and snippets.

View hereisfun's full-sized avatar

calvinfung hereisfun

View GitHub Profile
@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();
@hereisfun
hereisfun / pubSub.js
Created March 7, 2017 13:54
简单的pub/sub模式实现
var pubSub = (function(){
//以各种event为键,值为该event绑定的callback队列
var eventQueues = {};
//此处只发布event本身,不携带其它信息。
//可稍作修改增加参数实现携带信息。
function pub(event){
if(!eventQueues[event]){
//若发布event时没有该event对应的callback队列
eventQueues[event] = [];