1

consider i have many methods in jscript.. method1()

method2()

method3()

Now method1() and method2() are independent. where method3() is called by both the methods. I want to know from which method method3() is getting called. either method1() or method2()

1
  • @luiges90 hmmm yea it looks a duplicate. But i couldnot find it and thanks for the help :) Commented Sep 7, 2013 at 7:59

3 Answers 3

1

Here it is simple code

function method1(){ method3('method1'); } function method2(){ method3('method2'); } function method3(method){ alert(method); } 

Reference

Sign up to request clarification or add additional context in comments.

Comments

0

Here is the sample code which logs the Caller method name :

function method1(){ method3(); } function method2(){ method3(); } function method3(){ console.log(method3.caller.name); } method1(); // method1 method2(); // method2 

Comments

0

try this.

function method3() { alert("caller is " + arguments.callee.caller.toString()); } 

2 Comments

it displays method body also in alert like caller is function met1() { method3(); }
it says package arguments.callee doesnot exist

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.