Subj : Re: JavaScript problem To : netscape.public.mozilla.jseng From : Adrian Herscu Date : Sun Oct 12 2003 09:06 pm Brendan Eich wrote: > Adrian Herscu wrote: > >> I want o.f() to execute in caller's context and without passing the >> "this" reference as a parameter. >> >> A simplified version: >> >> function f() { >> alert( f.caller.p ); >> } >> >> >> function g() { >> f(); // executes in the default context - work >> f.call(this); // executes in a forced context - doesn't work > > > > f.caller in the second case will be Function.prototype.call -- the > native call method. It has no p property, of course. > Is there any reason behind this? After all, both call f(). Why the "caller" refers to different objects, depending on the call style? > > If you want to work in Mozilla and IE, you could either code both ways > and test user agent to decide which tine of the code fork to follow, or > you could loop over caller until you find p (and not more than twice). > > /be > >> } >> g.p = "hello"; >> >> g(); >> >> >> >> >> > .