[IMP] Improved shim for function.bind
bzr revid: nicolas.vanhoren@openerp.com-20130806130734-lov3aq0m4b1r4sto
This commit is contained in:
parent
baef37aec6
commit
e6e5fcde1e
|
@ -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",
|
||||
|
|
|
@ -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 = {};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue