Thomas Mlynarczyk wrote:
I stumbled over a strange behaviour of Mozilla. When I want to access the
caller property of a function that was not called from within another
function, Mozilla seems to abort the script. No error message, no hang, just
stopping script execution at that point. Why? And what is the remedy?
What kind of access do you try? Of course if there is no caller that
property is null so you can't do much with it.
The following test case works for me without problems in Firefox 1.0 and
in some recent Mozilla nightly:
<html lang="en">
<head>
<title>caller property of function</title>
<script type="text/javascript">
function f () {
var result = 'function f called : ';
result += 'typeof f.caller: ' + (typeof f.caller) + '; ';
result += 'f.caller: ' + f.caller;
document.write('<p>' + result + '<\/p>\r\n');
}
function g () {
f();
}
</script>
</head>
<body>
<h1>caller property of function</h1>
<script type="text/javascript">
f();
</script>
<script type="text/javascript">
g();
</script>
</body>
</html>
Output is
function f called : typeof f.caller: object; f.caller: null
function f called : typeof f.caller: function; f.caller: function g() {
f(); }
and I see nothing wrong with that, there is certainly no hang.
--
Martin Honnen
http://JavaScript.FAQTs.com/