Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i know from what function function call was invoked?

    Hello
    i have
    function foo(){
    blah()
    }

    how can i know in function blah() that it was called from function foo()?
    (and not from other function )

    thanks

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    hm... it depends why you need that for... Try using a parameter in fuction foo(param) with an if staement or whichever. Something like

    function foo(param){
    if(param = 'blabla'){
    blah()
    }
    }
    .
    .
    .
    <tag onclick="foo('blabla')">

    If you can be more specific....
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well of course you can add indictor as arg , but this is not the case here
    i can't add args (dont ask why i just can't ) .

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Than give the blah() an argument and use that as a sort of separator later (blah with and without arg...)

    function foo(){
    blah('arg')
    }

    Still don't see the final point of your need...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use the callee property:
    <html>
    <head>
    <script>
    function foo() {
    blah();
    }
    function blah() {
    var c=arguments.callee.caller;// gets the caller
    if (c==foo) {
    alert("Called from foo()");
    } else {
    alert("Called otherwise");
    }
    }
    </script>
    </head>

    <body>
    <form>
    <input type="button" value="Call blah() directly" onclick="blah()">
    <br><br>
    <input type="button" value="Call blah() through foo()" onclick="foo()">
    </form>
    </body>
    </html>

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great!
    tnx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •