From 3a432f80fe46d9a319648cfb596b271f84e4d004 Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 1 Dec 2010 16:20:28 +0000 Subject: [PATCH] support.js: add function bind (JS OOP trick) --- src/runtime/javascript/minibar/support.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runtime/javascript/minibar/support.js b/src/runtime/javascript/minibar/support.js index 9633cfb28..01c585414 100644 --- a/src/runtime/javascript/minibar/support.js +++ b/src/runtime/javascript/minibar/support.js @@ -4,6 +4,14 @@ function element(id) { return document.getElementById(id); } +/* --- JavaScript tricks ---------------------------------------------------- */ + +// To be able to object methods that refer to "this" as callbacks +// See section 3.3 of https://github.com/spencertipping/js-in-ten-minutes/raw/master/js-in-ten-minutes.pdf +function bind(f, this_value) { + return function () {return f.apply (this_value, arguments)}; +}; + /* --- JSONP ---------------------------------------------------------------- */ // Inspired by the function jsonp from