[IMP] Improved shim for function.bind

bzr revid: nicolas.vanhoren@openerp.com-20130806130734-lov3aq0m4b1r4sto
This commit is contained in:
niv-openerp 2013-08-06 15:07:34 +02:00
parent baef37aec6
commit e6e5fcde1e
3 changed files with 26 additions and 2 deletions

View File

@ -13,7 +13,6 @@ This module provides the core of the OpenERP Web Client.
'auto_install': True,
'post_load': 'wsgi_postload',
'js' : [
"static/src/fixbind.js",
"static/lib/datejs/globalization/en-US.js",
"static/lib/datejs/core.js",
"static/lib/datejs/parser.js",

View File

@ -11,6 +11,31 @@ if (typeof(console) === "undefined") {
});
}
// shim provided by mozilla for function.bind
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
var instance = openerp;
openerp.web.core = {};

View File

@ -547,7 +547,7 @@ openerp.Widget = openerp.Class.extend(openerp.PropertiesMixin, {
for (var name in this) {
if(typeof(this[name]) == "function") {
if((/^on_|^do_/).test(name)) {
this[name] = this[name].bind(this);
this[name] = _.bind(this[name], this);
}
}
}