If some big event handler is triggered too frequently, it will cause computer lagging.In my example $(window).resize(), I want the function to be called after the user has completed his resize, instead of firing every time you resize by a single pixel.So, I made this 'Function Buffer':function FtnBuff(){    var count=0;    var delay = 50;         var ftnList=[];    this.add = function(ftn){        if(isFunction(ftn)){            ftnList.push(ftn);        }else{            return false;        }    }    this.start = function(){        count ++;        setTimeout(checkbuff, delay);    }    this.setDelay = function(num){        if(!isNaN(num)){            delay = num;        }    }    function checkbuff(){        if(count==1){            runFtn();        }        count--;    }    function runFtn(){        for(var key in ftnList){            ftnList[key]();        }    }    function isFunction(obj) {        var getType = {};        return obj && getType.toString.call(obj) === '[object Function]';    }    return this;}Use case:ftnbuff = new FtnBuff()ftnbuff.add(aa)ftnbuff.add(function(){    bb('long time no C.')})$(window).resize(ftnbuff.start)function aa(){    console.log('This is aa.');}function bb(customText){    console.log('This is bb.'+customText);}
Function Buffer to avoid triggering an event handler too frequently
javascript;jquery;event handling