Other
27 Mar 2012
Function caller bug in Firefox 11 (solved)
A workaround for a bad surprise
The automatic update from Firefox 10 to 11 may have brought a bad surprise to many developers whose codes relied on functions of instantiated objects reading their own function caller properties.
function objProto(){
this.fnc = function(){
alert(this.fnc.caller);
}
}
var obj = new objProto();
function callingFunction(){
obj.fnc();
}
setTimeout(function(){
callingFunction();
},1500);
The output in Firefox 11 is null, while in previous versions and other browsers the output is
function callingFunction(){
obj.fnc();
}
But, fortunately, there is a simple workaround. Simply call the following function before
you let your object function read its own caller property:
function repairCallerProp(){
var x = repCallerProp.caller;
}
This is what it looks like if used in the example above:
function repairCallerProp(){
var x = repairCallerProp.caller;
}
function objProto(){
this.fnc = function(){
repairCallerProp();
alert(this.fnc.caller);
}
}
var obj = new objProto();
function callingFunction(){
obj.fnc();
}
setTimeout(function(){
callingFunction();
},1500);
That's it - I would be pleased if I could help you!
Comments
Add comment: