J
jackchang1
It's not difficult getting the function name of the caller but if the
caller is an object's method, how do you get the method name?
<html>
<head>
<script type="text/javascript">
function displayCallStack(func){
var caller = func.caller;
if(caller == null) return;
console.log(caller);
displayCallStack(caller);
}
function objectA(){
}
objectA.prototype.method1 = function(){
test();
}
var obj = new objectA();
function test(){
test1();
}
function test1(){
displayCallStack(displayCallStack);
}
</script>
<body onload="obj.method1()">
</body>
</html>
Here is the result:
test1()
test()
function()
onload(event)
Ideally, I like the output to be
test1()
test()
obj.method1()
onload()
Your help is highly appreciated!
caller is an object's method, how do you get the method name?
<html>
<head>
<script type="text/javascript">
function displayCallStack(func){
var caller = func.caller;
if(caller == null) return;
console.log(caller);
displayCallStack(caller);
}
function objectA(){
}
objectA.prototype.method1 = function(){
test();
}
var obj = new objectA();
function test(){
test1();
}
function test1(){
displayCallStack(displayCallStack);
}
</script>
<body onload="obj.method1()">
</body>
</html>
Here is the result:
test1()
test()
function()
onload(event)
Ideally, I like the output to be
test1()
test()
obj.method1()
onload()
Your help is highly appreciated!