summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorWilson Page <wilsonpage@me.com>2013-10-05 12:45:47 +0100
committerWilson Page <wilsonpage@me.com>2013-10-05 12:45:47 +0100
commitc0b9e7b9d75aa80028b1e28654713f98f0884800 (patch)
tree27b200542c08da7e78878cdf17512568f3351616 /index.js
parent16d5e9dc41c77404fda9832c4dbbfaec7ace217d (diff)
downloadfastdom-c0b9e7b9d75aa80028b1e28654713f98f0884800.zip
fastdom-c0b9e7b9d75aa80028b1e28654713f98f0884800.tar.gz
fastdom-c0b9e7b9d75aa80028b1e28654713f98f0884800.tar.bz2
Tidy up
Diffstat (limited to 'index.js')
-rw-r--r--index.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/index.js b/index.js
index 376f905..4c1f2f0 100644
--- a/index.js
+++ b/index.js
@@ -208,16 +208,18 @@
*/
FastDom.prototype.defer = function(frames, fn, ctx) {
if (frames < 0) return;
- var job = this._add('defer', fn);
+ var job = this._add('defer', fn, ctx);
+ var self = this;
+
(function wrapped() {
- if (frames-- === 0) {
- try { fn.call(ctx); } catch(e) {
- this.onError(e);
- }
- } else {
- job.timer = raf(wrapped);
+ if (!(frames--)) {
+ self.run(job);
+ return;
}
+
+ job.timer = raf(wrapped);
})();
+
return job.id;
};