Closures with functions as parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • limweizhong
    New Member
    • Dec 2006
    • 62

    Closures with functions as parameters

    Hi,

    Could anyone explain what happens when some function (x) is passed as a parameter into a function (b) which is nested inside a function(a), i.e.
    Code:
    a=function()
    {
      b=function(t)
      {
        // what scope chain does t have in here?
      };
      b(x); // where x is some random function that could be externally defined.
    };
    Last edited by Dormilich; Sep 27 '11, 04:12 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    hm, I don’t see anything special (functions are like any other variables) so I’d say the standard rules apply.

    edit: btw, you code is not a closure.
    Last edited by Dormilich; Sep 27 '11, 04:24 PM.

    Comment

    • limweizhong
      New Member
      • Dec 2006
      • 62

      #3
      Thanks for clarifying. I originally thought that running the parameter t as a function inside b would allow me to get to the variables inside a, or perhaps if t returns a function, that function would inherit the variables inside a. However, after some testing, I have found that it is incorrect.

      Comment

      Working...