Javascript function caller

Javascript (before 1.3) used to a property of the function variable arguments called caller which was the function that called the function in it. It was deprecated with 1.3. Turns out the function variable now has a caller in IE and FFx anyway, as proved by:


function f ( ) {
	alert (arguments.callee.caller);
}
			
function f_caller ( ) {
	f () ;
}

f();

f_caller ();

Now i just need to see if i can find a way of injecting variables into the scopes of those functions. I think at this point, i am out of luck. Gus?

Comments

Angus

The Gus-symbol on the sky! It's lit! Quick, Script-Boy, to the Codemobile! As far as I know each function has its own variable scope (as well as the arguments array scope which is different) and you can't access the variable scope from within another function unless you're using a closure. When writing OO code I usually have a global "data" hash/array or similar as a property of the main object and store anything important there. Pass a key name to any called functions and let them do their dirty work. It's cleaner than messing around with scopes anyway. P.S. if you absolutely *must* push something onto the local scope you can use the "with" keyword. It's a bad habit of mine, considered kinda deprecated these days.