function slow(o, delay) { delay = delay || 500; var q = queue(1); var state_props = []; // Get the current state of the object in javascript // time function getState() { var new_state = {}; for (var i = 0; i < state_props.length; i++) { new_state[state_props[i]] = o[state_props[i]]; } return JSON.stringify(new_state); } // Apply a state to the object function applyState(st) { var state = JSON.parse(st); for (var i in state) { o[i] = state[i]; } state = getState(); } for (var i in o) { if (typeof o[i] === 'function') { var old_function = o[i]; o[i + '_fast'] = old_function; o[i] = (function(old) { return function x() { var args = arguments; var state = getState(); q.defer(function(callback) { window.setTimeout(function() { applyState(state); old.apply(o, args); callback(); }, delay); }); }; })(old_function); } if (typeof o[i] === 'string' || typeof o[i] === 'number') { state_props.push(i); } } return o; }