summaryrefslogtreecommitdiff
path: root/lib/scripts/events.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/events.js')
-rw-r--r--lib/scripts/events.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/scripts/events.js b/lib/scripts/events.js
index 907526375..e7526ced7 100644
--- a/lib/scripts/events.js
+++ b/lib/scripts/events.js
@@ -156,4 +156,21 @@ function addInitEvent(func) {
}
}
-
+/**
+ * Bind variables to a function call creating a closure
+ *
+ * Use this to circumvent variable scope problems when creating closures
+ * inside a loop
+ *
+ * @author Adrian Lang <lang@cosmocode.de>
+ * @link http://www.cosmocode.de/en/blog/gohr/2009-10/15-javascript-fixing-the-closure-scope-in-loops
+ * @param functionref fnc - the function to be called
+ * @param mixed - any arguments to be passed to the function
+ * @returns functionref
+ */
+function bind (fnc) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ return function() {
+ return fnc.apply(this, args);
+ }
+}