diff options
author | Jingwei "John" Liu <liujingwei@gmail.com> | 2013-09-24 12:35:33 +0800 |
---|---|---|
committer | Jingwei "John" Liu <liujingwei@gmail.com> | 2013-09-24 12:35:33 +0800 |
commit | 734416eeb5c447dc64a2145f9b664a07170f9b3e (patch) | |
tree | 1b46273b9e3edd4ddc85945c6ac270f33a265b60 | |
parent | 53288b2e2c239515518d1c98f16edc0820aed8ab (diff) | |
download | fastdom-734416eeb5c447dc64a2145f9b664a07170f9b3e.zip fastdom-734416eeb5c447dc64a2145f9b664a07170f9b3e.tar.gz fastdom-734416eeb5c447dc64a2145f9b664a07170f9b3e.tar.bz2 |
Accept context for deferred jobs
-rw-r--r-- | lib/fastdom.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/fastdom.js b/lib/fastdom.js index 036a2dc..80b799f 100644 --- a/lib/fastdom.js +++ b/lib/fastdom.js @@ -197,14 +197,19 @@ * by the number of frames * specified. * - * @param {Function} fn - * @param {Number} frames + * @param {Function/Object} job + * @param {Number} frames * @api public */ - FastDom.prototype.defer = function(fn, frames) { + FastDom.prototype.defer = function(job, frames) { + // Accepts a function or an object + // consists of function and its context + var fn = job.fn || job; + var ctx = job.ctx || null; + (function wrapped() { if (frames-- === 0) { - try { fn(); } catch (e) { + try { fn.call(ctx); } catch (e) { if (this.onError) this.onError(e); } } else { @@ -266,4 +271,4 @@ window['fastdom'] = fastdom; } -})(window.fastdom);
\ No newline at end of file +})(window.fastdom); |