[turboid] javascript solutions

Home     Contact     Search     About me
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.
Recently, after Firefox had updated itself to version number 11, I had a bad surprise. I discovered that the function caller property in a certain situation contains the null value instead of the function expected. An important part of the Turboid framework didn't work anymore. The situation I am speaking about is when an object function reads its own caller property, for example this way:
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:

Name: (required)
E-Mail: (required, remains invisible)
Website:
Comment:
Please check all (anti-spam):