SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast ZefQ's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post variable that points to a function

    hey is there a way for the function to return to the call function when its done..
    i dont want to use return cuz i want it to begin from the begining of the call function.

    and i cant use functionName() cuz its diffrent function that uses it.

    can u do something like this

    Code JavaScript:
    function callFunction () {
         functionName(callFunction());
    }
     
    function functionName(callFunction) {
         if(1==1)
              callFunction;
    }
    Last edited by ZefQ; Nov 14, 2008 at 03:22.

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    You're talking about recursion, but you'll want to handle your coding VERY carefully to ensure that you don't end up causing your coding to loop infinitely. Doing what you're suggesting is very dangerous.

    Here's a quick and dirty example to show what I'm talking about. A way to find the first empty element on a series of like named fields:
    Code JavaScript:
    <script type="text/javascript">
     var LastEmptyFieldID = loopIt(1);
     // find the first empty field...
     function loopIt(FieldID) {
      var thisField;
      var nextField;
      var nextFieldID = FieldID++;
      thisField = document.getElementByID("fieldName" + FieldID);
      nextField = document.getElementByID("fieldName" + nextFieldID);
      if (nextField != null)
      {
       nextFieldID = loopIt(nextFieldID);
      }
      return nextFieldID;
     }
    </script>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    SitePoint Enthusiast ZefQ's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from what i can see in your code that is not what im talking about.

    the funktion that i want to call is a function that rezises a div animated depending on diffrent varibles
    Code JavaScript:
    function foo() {
         if(i==0)
              rezise(v,a,r,i,a,b,l,e,)
         else
              bar()
    }
    function rezise(v,a,r,i,a,b,l,e,) {
         if(size < newSize){
              lots of code
         }
         else {
              i++;
              backToTheFunctionThatCalled()
             /*in this case foo, but in the script it can be 
             called by other functions to so i 
             need something that can see witch 
             function did the request and then return 
             it to the top of that function*/
         }
    }

    ofcurse i could do somthing like

    resize(variables, "one")

    resize(blabla, func){
    ...

    if(func=="one")
    oneFunc();
    else
    otherfunc();
    }

    but i want somthing more flexible..
    Last edited by ZefQ; Nov 14, 2008 at 03:17. Reason: ...

  4. #4
    SitePoint Enthusiast ZefQ's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...

    solved

    this was what i was looking for

    eval(callFunc + '()');
    Last edited by ZefQ; Nov 14, 2008 at 04:28.


Bookmarks

Posting Permissions

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