SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow calling another function inside a function? how?

    hi guys i'm very noobs on javascript

    how do you call a function inside a function?
    can you show me a simple but complete snippet of codes?

    thank you very much.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can only access a nested function within its containing function. Variables defined in the outer functions body are accessible from the inner function, but not the other way around. I hope that made sense...

  3. #3
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by solidcodes View Post
    hi guys i'm very noobs on javascript

    how do you call a function inside a function?
    can you show me a simple but complete snippet of codes?

    thank you very much.
    If you have this:
    Code:
    function foo() {
      var i
      function bar() {
        alert(i);
      }
    }
    Then you cannot call "bar" from outside of the "foo" function.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the other hand, you can do this:

    Code:
    function foo() {
         bar();
    }
    
    function bar() {
         return;
    }
    Last edited by dwees; Jan 11, 2007 at 10:31. Reason: I doubt someone inexperienced in Javascript wants to use a nested function.

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is not a nested function though

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right it isn't but it's probably what the OP wants.


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
  •