Subj : Re: JavaScript problem To : netscape.public.mozilla.jseng From : Adrian Herscu Date : Sun Oct 12 2003 07:29 pm Brendan Eich wrote: > Martin Honnen wrote: > >> Well, it is "working" in Mozilla too, only with a different result. >> Change your code to >> >> var o = new function() { >> var This = this; >> >> this.f = function() { >> alert( This.f.caller ); >> } >> } >> >> function g() { >> o.f.call(this); >> } >> g.p = "hello"; >> >> g(); >> >> and you will see what the caller function is, in Mozilla's case it is >> the function >> call >> in IE's case it is the function >> g >> so that is why you get a different result (when reading the p property). >> The caller property is nowhere defined in the ECMAScript edition 3, >> indeed there are implementation like Opera 7's ECMAScript >> implementation which do not implement caller at all. >> It is therefore not possible to decide which implementation is right >> as the spec doesn't tell. >> >> With Mozilla you need to access >> This.f.caller.caller >> if you are looking for the function g. >> > > Or don't invoke f using call, just call o.f(this) inside g. > > /be > That's the point! 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 } g.p = "hello"; g(); .