summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2012-01-12 09:49:10 +0100
committerXavier Morel <xmo@openerp.com>2012-01-12 09:49:10 +0100
commit12e3ef7fbfd8f3a45f1e995a9261d1d12496a31b (patch)
tree8599ab0d173ce4fc46bf48f7903ae2d0fd2a9e10 /addons/web/static/src/js/core.js
parentc92b29e3f9b7151eeddf0ef8109f8c72f7b2304e (diff)
[IMP] add lazier proxy method on CallbackEnabled, use it in WebClient and ListView
bzr revid: xmo@openerp.com-20120112084910-6fxbzbgmv51utyko
Diffstat (limited to 'addons/web/static/src/js/core.js')
-rw-r--r--addons/web/static/src/js/core.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js
index a194c34f287..d5c096d5a2a 100644
--- a/addons/web/static/src/js/core.js
+++ b/addons/web/static/src/js/core.js
@@ -348,6 +348,31 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca
}
}
}
+ },
+ /**
+ * Proxies a method of the object, in order to keep the right ``this`` on
+ * method invocations.
+ *
+ * This method is similar to ``Function.prototype.bind`` or ``_.bind``, and
+ * even more so to ``jQuery.proxy`` with a fundamental difference: its
+ * resolution of the method being called is lazy, meaning it will use the
+ * method as it is when the proxy is called, not when the proxy is created.
+ *
+ * Other methods will fix the bound method to what it is when creating the
+ * binding/proxy, which is fine in most javascript code but problematic in
+ * OpenERP Web where developers may want to replace existing callbacks with
+ * theirs.
+ *
+ * The semantics of this precisely replace closing over the method call.
+ *
+ * @param {String} method_name name of the method to invoke
+ * @returns {Function} proxied method
+ */
+ proxy: function (method_name) {
+ var self = this;
+ return function () {
+ return self[method_name].apply(self, arguments);
+ }
}
});