1 /* Buffered DOM updates */
2 var Buffer = Class.extend({
4 init: function(callback, callback_this) {
5 this._callback = callback;
6 this._callback_this = callback_this;
8 this._num_elements = 0;
9 this._elements = Array();
11 this._interval = 1000;
16 add: function(element)
18 this._elements.push(element);
19 if (this._num_elements == 0) {
20 this._timerid = setInterval(
21 (function(self) { //Self-executing func which takes 'this' as self
22 return function() { //Return a function in the context of 'self'
23 console.log("running callback");
24 clearInterval(self._timerid);
25 self._callback.apply(self._callback_this);
34 var elements = this._elements;
35 this._elements = Array();
36 this._num_elements = 0;