Larry Zhao

co-founder of jianshu.com, developer, game lover and soccer fan.

arguments.callee.caller bug in Internet Explorer 9

Just found an IE9 bug with my colleague these days, it’s about how to get the caller of the function and it’s confirmed by Microsoft Internet Explorer team.
In older days, arguments.callee.caller is often used for retrieving the caller of the function. It works perfect in IE8 and Chrome. But recently I found it doesn’t work in IE9.
Considering the following code piece:

function func1(flag){
   if(flag){
      alert("Caller is here!");
   }else {
      func2();
   }
}

function func2(){
   arguments.callee.caller(true);
}

If I trigger func1(false) on my page, in Firefox/Chrome/IE8, the alert box will come out successfully as expected. But in IE9, you will get the following error in the console:

Then we consulted Internet Explorer Team of Microsoft about this. They confirmed that this is a little bug of IE9, and also they suggested that it would be corrected to code like this:

  function func1(flag){
   if(flag){
      alert("Caller is here!");
   }else {
      func2();
   }
}

function func2(){
   var callerFunc = arguments.callee.caller;
   callerFunc(true);
}

Furthermore, in MDN, Function.caller is proposed to be used in the case of arguments.callee.caller, but still, in IE9 it’s not working.

Hope this post will help you when you have this rare problem. My IE9 version is: 9.0.8112.16421
and here is the test html: caller.html

comments powered by Disqus