Prints out a stack trace

[Total: 0    Average: 0/5]

This file shows how to have javascript show you the order in which functions have been called.

Body Code:

<script type=text/javascript>
function print1(x) { x+="."; print(x);}
function print(x)  {
  document.write(stacktrace())
  document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parameter = "+x+"<BR>")
}

function funcname(f) {
 var s = f.toString().match(/function (w*)/)[1];
 if ((s == null) || (s.length==0)) return "anonymous";
 return s;
}
function stacktrace() {
 var s = "";
 for (var a = arguments.caller; a !=null; a = a.caller) {
   s += "->"+funcname(a.callee) + "n";
   if (a.caller == a) {s+="*"; break;}
 }
 return s;
}
print1("TEST")
print1("THIS")
</script>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *